Explain the keyword continue.• It is used to take the control to the beginning of the loop. • It bypasses the statements inside the loop, which have not been executed. • Continue statement is generally present within a loop and associated with if statement. Example: int i, j; for ( i=1 ; 1<=2 ; i++) { for ( j=1 ; j<=2; j++) { if (i==j) continue ; printf (“\n%d %d\n”,i,j); } }
Output of program is 12 21 When the continue statement takes control it bypasses the remaining statements of the inner for loop.
|
How are decisions made using a switch keyword?• Switch is combined with case and default keywords to make a control statement. • Syntax: switch(integer expression) { case constant 1: do this; case constant 2: do this; case constant n: do this; default: do this; } • The integer expression yields an integer value. • This integer value is matched with case constant and if condition for any case is true it executes the statements following the case statement. • If no case matches then statements following default are executed.
|
What is the K & R method to declare formal arguments in a function .• K & R is called as the Kernighan and Ritchie method of declaring arguments. Example:
calsum(x, y, z) int x, y, z; here x,y,z are the formal parameters. • Here the values x, y, z are defined in the first statement (function declaration). • Their data types are defined in the second statement.
|
Give one method for declaration of formal parameters.• Formal parameters can be declared using ANSI method . • In this method the data types of the parameters are defined in the function declaration. • The data types used can be integer, float, char, etc. • Example: calsum(int x, int y, int z)
Here x,y,z are the formal parameters.
|
What is garbage value and how it can be avoided?• If a function is not returning any specific value ,it returns data called garbage value. Example:
return(a); A return ; B • In statement A a specified value ‘a’ is returned. In statement B no specified value present so it returns a garbage value. • To avoid the garbage value keyword void is placed before the function name. Example:
void display ( ) { printf (“welcome”); }
|
Give the difference between call by value and call by reference.• When a function is called it passes values of variables to called functions. • This is called as call by value and we have access to formal parameters. Example: sum= calsum( a, b, c);
Here calsum is the function and a, b, c are the values passed. • If instead of the values the addresses of value are passed it is called as call by reference. • To pass values using call by reference pointers are used and we have access to actual parameters.
|
Which variables always contain whole numbers?• Pointers are the variables which always contain data in the form of whole numbers. • They store the address of other variables. • They are declared as data type *name of variable. • It also uses other operator ‘&’ which returns the address of the variable. Example: j= &i Here j is a variable that holds the address of other variable i.
|
Explain recursion.• A function is called recursive if a statement within the function can call the same function. • In circular definition it is the process of defining something in terms of itself. • It is represented as rec( ). • An if statement is used within recursive statement to avoid infinite loop. Example:
rec ( int x) { int f; if (x== 1) return ( 1 ); else f=x*rec(x-1); return ( f ); } Function to find the factorial of a number.
|
Can user defined functions be added to the library ?If yes, explain.• Yes, the user defined functions can be added to the library. • Also different compilers provide different utilities to modify functions and for c compilers utility called “tlib.exe” (Turbo library) is used. • Initially create the function and then compile the file using Alt f9. • This file contains the code in machine language and then add file to the library using the command “ c:\.>tlib math.lib + c:\filename.obj “ • Declare the prototype of function in the header file. • To include it in a program use syntax : #include “c:\\filename.h”.
|
Explain the automatic and static storage classes.• Automatic and static storage classes for variables defined uses memory as the storage. • These classes are local to the block in which variables are defined. • Automatic class uses the garbage value as the default initial value. • Static class uses the default initial value as zero. • These classes remain till the control remains within block in which the variable is defined.
|