Posts

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