Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Functions Questions
In C, what does this recursive function return for the input 123, and why is the result printed twice? #include
int sumdig(int); int main() { int a, b; a = sumdig(123); b = sumdig(123); printf("%d, %d ", a, b); return 0; } int sumdig(int n) { int s, d; if(n!=0) { d = n%10; n = n/10; s = d+sumdig(n); } else return 0; return s; }
In C, what will this program print? Note the comma operator in the function and the space in printf. #include
int addmult(int ii, int jj) { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } int main() { int i=3, j=4, k, l; k = addmult(i, j); l = addmult(i, j); printf("%d %d ", k, l); return 0; }
In C pointer arithmetic on arrays: what is printed when the function advances a char* pointer over an initialized array? #include
int main() { void fun(char*); char a[100]; a[0] = 'A'; a[1] = 'B'; a[2] = 'C'; a[3] = 'D'; fun(&a[0]); return 0; } void fun(char *a) { a++; printf("%c", a); a++; printf("%c", a); }
In C, function pointers and predicates: what does this program print when comparing equal integers? #include
int fun(int, int); typedef int (*pf) (int, int); int proc(pf, int, int); int main() { printf("%d ", proc(fun, 6, 6)); return 0; } int fun(int a, int b) { return (a==b); } int proc(pf p, int a, int b) { return ((*p)(a, b)); }
In C, trace control flow with a global controlling a while loop and a recursive call to main(). What is printed? #include
int i; int fun(); int main() { while(i) { fun(); main(); } printf("Hello "); return 0; } int fun() { printf("Hi"); }
In C, analyze recursion via calling main() from main() and a toggled local variable. What is printed? #include
int main() { int i=1; if(!i) printf("CuriousTab,"); else { i=0; printf("C-Program"); main(); } return 0; }
In C, passing main as a function pointer: what is the program output order? #include
int fun(int(*)()); int main() { fun(main); printf("Hi "); return 0; } int fun(int (*p)()) { printf("Hello "); return 0; }
In C function-call nesting and assignment evaluation, what will this program print? #include
int fun(int i) { i++; return i; } int main() { int fun(int); int i = 3; fun(i = fun(fun(i))); printf("%d ", i); return 0; }
In C, evaluate nested assignments and function calls: what does this program print for k? #include
int func1(int); int main() { int k = 35; k = func1(k = func1(k = func1(k))); printf("k=%d ", k); return 0; } int func1(int k) { k++; return k; }
On a 16-bit Turbo C (DOS) platform using compiler registers, what will this program print? #include
int main() { int fun(); int i; i = fun(); printf("%d ", i); return 0; } int fun() { _AX = 1990; // set return register (Turbo C extension) for int }
In C, passing by address and modifying in-place: what does this program print? #include
void fun(int*, int*); int main() { int i = 5, j = 2; fun(&i, &j); printf("%d, %d", i, j); return 0; } void fun(int *i, int *j) { *i = *i * *i; *j = *j * *j; }
Post-increment in a return and pre-decrement in printf: what is printed? #include
int main() { int fun(int); int i = fun(10); printf("%d ", --i); return 0; } int fun(int i) { return (i++); }
Recursion with post-decremented actual argument: what does this program do? #include
int reverse(int); int main() { int no = 5; reverse(no); return 0; } int reverse(int no) { if (no == 0) return 0; else printf("%d,", no); reverse(no--); }
Type conversions with nested calls and assignment to a float: what prints? #include
int fun(int); int main() { float k = 3; fun(k = fun(fun(k))); printf("%f ", k); return 0; } int fun(int i) { i++; return i; }
Recursion with pre-decrement on both sides of a print: what is the output sequence? #include
void fun(int); typedef int (*pf)(int, int); int proc(pf, int, int); // (not used) int main() { int a = 3; fun(a); return 0; } void fun(int n) { if (n > 0) { fun(--n); printf("%d,", n); fun(--n); } }
Diagnose the conditional expression and returns: what does this program do? #include
int check (int, int); int main() { int c; c = check(10, 20); printf("c=%d ", c); return 0; } int check(int i, int j) { int *p, *q; p = &i; q = &j; i >= 45 ? return(*p) : return(*q); }
Simple conditional return in C: given i=45, what does this program print? #include
int check(int); int main() { int i = 45, c; c = check(i); printf("%d ", c); return 0; } int check(int ch) { if (ch >= 45) return 100; else return 10; }
In C programming, what will be the actual output of this program (consider control flow and the call to exit): #include
#include
int main() { int i = 0; i++; if (i <= 5) { printf("CuriousTab"); exit(1); main(); } return 0; } Choose the exact behavior/output.
C language semantics: “In C, all functions except main() can be called recursively.” Decide whether this statement is correct or incorrect.
C return semantics: “Functions cannot return more than one value at a time.” Decide whether this statement is correct or incorrect.
1
2
3
4
5