Sie sind auf Seite 1von 4

*********************************************************************** *********************** FUNCTIONS ********************

*********************************************************************** 1] What would be the output of the following program? main() { int a,b; a = sumdig(123); b = sumdig(123); printf(" %d %d",a,b); } sumdig(int n) { static int s = 0; int d; if( n != 0) { d = n % 10; n = (n - d) / 10; s = s + d; sumdig(n); } else return(s); } 2] What error would the following function give on compilation? f(int a, int b) { int a; a = 20; return a; } OPTIONS: (a) (b) (c) (d) Missing parenthesis in return statement. The function should be defined as 'int f(int a,int b)'. Redeclaration of 'a'. None of the above.

3] There is a mistake in the following code. Add a statement in it to remove it. main() { int a; a = f(10,3.14); printf("%d",a); } f(int aa, float bb)

{ return ((float) aa + bb); } 4] Point out the error in the following code. main() { int a = 10; void f(); a = f(); printf("\n %d",a); } void f() { printf("Hi"); } 5] Point out the error, if any, in the following function. main() { int b; b = f(20); printf(" %d",b); } int f(int a) { a>20? return(10): return(20); } 6] A function cannot be defined inside another function. <True / False> Will the following functions work? f1(int a,int b) { return(f2(20)); } f2(int a) { return(a * a); } 8] What are the following two notations of defining functions known as: int f(int a, float b) { /* some code */ } commonly <Yes / No>

7]

int f(a,b) int a; float b; { /* some code */ } 9] In a function two return statements should never occur. <True / False>

10] In a function two return statements should never occur successively. < True / False> 11] In C all functions except 'main()' can be called recursively. < True / False> Usually recursion works slower than loops. < True / False>

12]

13] Is it true that too many recursive calls may result int stack overflow? <Yes / No> 14] How many times the following program would print 'Jamboree'? mani() { printf)"\n Jamboree"); main(); } OPTIONS: (a) (b) (c) (d) Infinite number of times 32767 times 65535 times Till the stack doesn't overflow.

*********************************************************************** ************************ ANSWERS ***********************

***********************************************************************

1] 2] 3]

6 12 C Add the following function prototypw in amin(): float f(int, float);

4] In spite of defining the function 'f()' as returning 'void', the prog ram is trying to colect the value returned by 'f()' in the variable 'a'. 5] 'return' statement cannot be used as shown withe the ators. Instead the following statement may be used: return(a > 20 ? 10: 20); 5] 7] True. Yes. conditional oper

8] The first one is known as ANSI notation and the second is known as Kernighan and Ritchie or simply, K & R notation. 9] 10] 11] 12] 13] 14] 12] False. True. False. Any function including 'main()' can be called True. Yes. D. recursively.

Das könnte Ihnen auch gefallen