Posts

Showing posts from March, 2022

Break and continue

Break Keyword: The break keyword is used to break the flow of iteration and come out from the loop. It is also used in switch...case to come out from the scope if the particular case is matched. Here if we do not write a break statement in the switch...case then the flow will continue to execute until the next break statement is encountered or until the scope ends. Syntax: break; Example: for(i=i; i<=5; i++) {     if(i==3)          break;     printf("%d, ", i); } Continue Keyword: The continue keyword is used to skip the iteration only once and continue afterward. Syntax: continue; Example: for(i=i; i<=5; i++) {     if(i==3)         continue;     printf("%d, ", i); }

Actual and Formal Parameters

User-defined Function: User-defined is a function that is not part of a library but is defined by the user itself. Actual Parameters: Values that are passed to the called function from the main function are known as Actual parameters. Actual parameters are also called "Arguments". Formal Parameters: The variables declared in the function prototype or definition are known as Formal parameters. Example: Actual parameters: void main() {      int a=5, b=6;     add(a, b); } Here "a" and "b" are actual parameters in the call add(a, b). Formal parameters: void add( int x, int y) {     printf("Addition is = %d",(x+y)); } Here "x" and "y" are formal parameters in the statement void add( int x, int y). When a method is called, the formal parameter is temporarily "bound" to the actual parameter. Drafted on 🌏 by, Jal ☮ peace

Strings

String:     A string is a one-dimensional array of characters terminated by a null ('\ 0 '). Declaration of string: We can declare a string in C by making an array of char data-type. Syntax: char array-name[size]; Example: char name[10]; The above example will make 10 characters long string which is essentially an array of 10 characters. Null character: For string, each character in the array occupies one byte of memory, and the last character must always be null ('\ 0 ') . the termination character ('\ 0 ') is important in a string to identify where the string ends. Example: char name[10] = { 'I', 'R', 'O', 'N', 'M', 'A', 'N', '\ 0 ' } ; Drafted on 🌏 by, Jal ☮ peace

Pointers

  Pointer:     Pointer is a variable that  stores the address/reference  of  another variable . Declaration of a pointer variable: Syntax: data-typ e * ptr_variable_name; Example: int * p; Here p is declared as a pointer variable. Initialization of a pointer variable: Syntax: * ptr_variable_name = &other_variable_name;; Example: int a=10; int * p; * p = &a; Here the address of variable "a" is stored in pointer variable "p". And we can access the value at that address which is in fact the value of the variable "a" by placing " * " before the variable "p". i.e. " * p". Drafted on 🌏 by, Jal ☮ peace

File opening modes

File opening modes: We can perform  different operations on a file based on the file opening modes Note:  If a student had written any 3 of the following then the answer is correct. Mode Description r Open the file for reading only. If it exists, then the file is opened with the current contents; otherwise, an error occurs. w Open the file for writing only. A file with a specified name is created if the file does not exist. The contents are deleted if the file already exists. a Open the file for appending (or adding data at the end of the file) data to it. The file is opened with the current contents safe. A file with the specified name is created if the file does not exist. r+ The existing file is opened to the beginning for both reading and writing. w+ Same as w except both for reading and writing. a+ Same as a except both for reading and writing. Note:  The main difference is w+ truncate the file to zero length if it exists or creates a new file if it doesn't. While r+ neither d

Function prototype and definition

Function Prototype: A function prototype is also known as a function declaration. A function declaration tells the compiler about a function name and how to call the function. It defines the function before it is being used or called. A function prototype needs to be written at the beginning of the program. Syntax: return-type function-name ( arg-1, arg-2, ... ); Example: void addition( int, int ); Function Definition: A function definition defines the functions header and body. A function header part should be identical to the function prototype. Function return type Function name List of parameters A function body part defines function logic. Function statements Syntax: return-type function-name( arg-1, arg-2, ... ); {         //... function body } Example: void addition( int x, int y) {     printf("Addition is = %d ",(x+y)); } Drafted on 🌏 by, Jal ☮ peace

Array

Array (Definition):     An array is a  fixed-size sequential  collection of elements of the  same data types  grouped under a  single variable name . Declaring a one-dimensional array: Syntax: data-type variable-name [ size ]; Example: int mark[ 5 ]; float avg[ 5 ];      By default array index starts with 0 .      If we declare an array of size 5 then its index ranges from 0 to 4.      The first element will be stored at mark[ 0 ] and the last element will be stored at mark[4] not mark[5].      Like integer and float array we can declare an array of type char. Initializing and accessing the array: int mark[ 5 ] = {10,20,30,40,50}; printf("%d",mark[ 0 ]); printf("%d",mark[ 1 ]); printf("%d",mark[ 2 ]); printf("%d",mark[ 3 ]); printf("%d",mark[ 4 ]); Drafted on 🌏 by, Jal ☮ peace

Differentiate entry control and exit control loop.

  Difference between Entry control loop and Exit control loop: Basic Of Comparision Entry Controlled Loop Exit Controlled Loop Description Entry controlled loop is a loop in which the test condition is checked first, and then the loop body will be executed. Exit controlled loop is a loop in which the loop body is executed first and then the given condition is checked afterward. False Test Condition If the test condition is false, the loop body will not be executed. If the test condition is false, the loop body will be executed at least once. Example Examples of entry-controlled loops include, for loop and while loop. An example of an exit controlled loop is do…while Loop. Use Entry controlled loops are used when checking of test condition is mandatory before executing the loop body. Entry controlled loop is used when checking of test condition is mandatory after executing. Drafted on 🌏 by, Jal ☮ peace

Algorithm and Flowchart

Image
  Algorithm (Definition):     An algorithm  is a  finite sequence  of  well-defined steps  for  solving a problem . or     An algorithm is a  complete ,  detailed , and  precise step-by-step method  for  solving a problem  independently. Flowc hart (Definition):     A flowchart  is a  pictorial  or  graphical representation  of a  program  or an  algorithm . or     A flowchart is a  pictorial representation  of an  algorithm  depicting the  flow of various steps. Algorithm to find whether the number is even or odd: Step 1: Read no. Step 2: If no mod 2 = 0, go to step 4. Step 3: Print no is odd, go to step 5. Step 4: Print no is even. Step 5: Stop Flowchart to find whether the number is even or odd: Drafted on 🌏 by, Jal ☮ peace

What is Software?

Software (Definition): A set of instructions in a logical order to perform a meaningful task is called a program and a set of programs is called software. It tells the hardware how to perform a task. Types of software 1. System software  It is designed to operate the computer hardware efficiently. Provides and maintains a platform for running application software. Examples: Windows, Linux, Unix, etc. 2. Application software It is designed to help the user to perform a general task such as word processing, web browser, etc. Examples: Microsoft Word, Excel, PowerPoint, etc. Categories of System software: i. Operating system It controls hardware as well as interacts with users, and provides different services to users.  It is a bridge between computer hardware and the user.  Examples: Windows XP, Linux, UNIX, etc… ii. System support software It makes the working of hardware more efficient.  For example drivers of the I/O devices or routine for socket programming, etc… iii. System developm

C tokens

C Token (Definition): The smallest individual unit of a program is known as a token. C has the following tokens: Note: If a student had written any 3 of the following then the answer is correct. Keywords: C reserves a set of 32 words for its own use. These words are called keywords (or reserved words), and each of these keywords has a special meaning within the C language. Identifiers: Identifiers are names that are given to various user-defined program elements, such as variables, functions, and arrays. Constants: Constants refer to fixed values that do not change during the execution of the program. Strings: A string is a sequence of characters terminated with a null character \0. Special Symbols: Symbols such as #, &, =, * are used in C for some specific function are called special symbols. Operators: An operator is a symbol that tells the compiler to perform a certain mathematical or logical operation. Drafted on 🌏 by, Jal ☮ peace