Study C MCQ Questions and Answers on Functions and Pointers. Questions are on Recursion, Pass by Value and Pass By Reference. Attend C technical interviews easily after reading these Multiple Choice Questions.
Go through C Theory Notes on Functions before reading questions.
Yes. There is no limit on the number of functions in a C Program.
main() is a compulsory function with or without returning anything.
void main(){}
int main(){return 0;}
At least there will be one function which is main() function.
static void show(); int main() { printf("ROCKET "); show(); return 0; } static void show() { printf("STATIC"); }
Yes. A function can be static. Remember that a static variable or function has only FILE scope. You can use this function outside of the defined file even with extern static void show() prototype declaration.
There is no limit on the number of statements that can present in a C Function.
Remember that a C function name can not start with a number but it can contain contain numbers after 1st character is either an Underscore ( _ ) or an Alphabet.
int main() { int b=25; //b memory location=1234; int *p = b; printf("%d %d", b, p); return 0; }
Integer Pointer *p copied the value of b to a new memory location. Its is same as int p= b;. Only p=&b points to the same memory of b.
int main() { int b=25; //b memory location=1234; int *p; p=&b; printf("%d %d %d", &b, p); return 0; }
Integer pointer is declared by int *p. p=&b makes pointer P to point the address of b. So &b and p hold only address.
int a=10, *p; p = &a; printf("%d %d", a, *p);
&b gives ADDRESS OF b. *p gives VALUE AT memory location of b.
#include int sum(int,int); int main() { int a=5, b=10, mysum; mysum = sum(a,b); printf("SUM=%d ", mysum); printf("SUM=%d", sum(10,20)); return 0; } int sum(int i, int j) { return (i+j); }
You can call a function sum(10,20) inside another function printf directly.
20.0 is float. But char j is Character type. So, it is a mismatch. Here exactly two arguments are passed and two arguments are received.
int main() { sum(10, 20.0); return 0; } int sum(int i, char j) { return 10; }
int main() { printf("funny=%d" , funny()); return 0; } funny() { }
By default, a return 0; is added at the end of any function if not explicitly specified.
void funny2(); int main() { printf("funny2=%d" , funny2()); return 0; } void funny2() { }
void function does not return anything.
fprintf is used along with files. There is no library function PRINTF2().
int funny() { //return 0; is added by compiler. }
int funny2() { funny2(num); }
This recursive function hangs the CPU as there is no come out condition with IF.
int bunny(int,int); int main() { int a, b; a = bunny(5, 10); b = bunny(10, 5); printf("%d %d", a, b); return 0; } int bunny(int i, int j) { return (i, j); }
Do not try to put the same return (a,b). It is a bad practice to return 2 values at a time. You can return only one value. Value right side value return j works every time.