1.
pf1 is a pointer to a function: float, char -> int*
pf1 is a pointer to a function taking a float and a char as input, returning a pointer to an int
2.
pf2 is a pointer to a function: (float -> char) -> int*
pf2 is a pointer to a function that takes a function: float -> char as input and returns int*
3.
pf3 is a pointer to a function: float -> (char -> int*)
pf3 is a pointer to a function taking a float as input, returning a pointer to a function taking a char as input, returning a pointer to an int.
4.
pf4 is a pointer to a function: (float -> char) -> (char -> int*)
5.
pf5 is a pointer to a function: ((float, int -> void) -> char) -> (float, char -> (void -> int*))
6.
f1 is a function: float, char -> int*
7.
f2 is a function: (float -> char) -> int*
8.
f3 is a function: float -> (char -> int*)
9.
f4 is a function: (float -> char) -> (char -> int*)
10.
f5 is a function called as shown below
void *ptr = 0;
int *(*(*(*pf)(char(*)(void(*)(float,int))))(float, char))(void) = f5(ptr);
11.
What value will be printed?
#include <stdio.h>
#define get(i, T) *(((T*[]){ say_hi(&i), (i>3 ? &i : ((T*[]){&i, (T*)(i=5)})[0]), say_bye(&i) })[1])
void *say_hi(int *i){
// printf("hi\n");
++*i;
return 0;
}
void *say_bye(int *i){
// printf("bye\n");
*i *= 2;
return (void*)(*i > 4);
}
int main(){
int i = 1;
printf("%d\n", get(i, int));
return 0;
}
12.
Which line(s) would not cause any problem (during compilation or runtime) if uncommented?
int main(){
int i = 1, *p = &i;
// **(int**)&p = 2; // option 1
// ***(int*(*)[])&p = 2; // option 2
// ***(int***)&p = 2; // option 3
// ***(int**[])&p = 2; // option 4
return 0;
}
13.
What will be the output?
#include <stdio.h>
int main(){
int i = 1, j = 2;
int *arr1 = &i;
int arr2[] = {i, j};
printf("%d, %d\n", arr1 == &arr1, arr2 == &arr2);
return 0;
}
14.
Which line(s) would not cause compilation error if uncommented?
int main(){
int i = 1, j = 2;
// int arr[] = &i; // option 1
// int *arr[] = &i; // option 2
// int (*arr)[] = &i; // option 3
// int arr = (int)&i; // option 4
return 0;
}
15.
Which line(s) would cause compilation error if uncommented?
#include <stdio.h>
#define _S(x) s##x
#define S(x) _S(x)
int main(){
// { struct _S(_S(_S(0))){} sss0; } // option 1
// { struct S(S(S(0))){} sss0; } // option 2
// { struct _S(S(s0)){} sss0; } // option 3
// { struct S(_S(s0)){} sss0; } // option 4
return 0;
}
16.
What keys should you press for the string "You got it!" to be printed?
#include <stdio.h>
int main(){
char c = 0;
scanf("%c", &c);
scanf("%c", &c);
printf("%s", c != 10? "You got it!" : 0);
return 0;
}
17.
Which one declares an array of pointers to a 2D array of functions: void -> void ?
18.
Which one declares a function taking an integer and returning an array of pointers to a 2D array of functions: void -> void ?
19.
Why the compiler gets rid of the if-else condition in the code given below when -O2 flag is used?
#include <stdio.h>
extern int i;
int main(){
if(i + 1 > i) printf("wtf");
else printf("ok");
return 0;
}
20.
What will be the output (assume pointer size is 8 bytes, int size is 4 bytes, char size is 1 byte)?
#include <stdio.h>
int main(){
int i = 1;
printf("%ld, ", (char*)(((int*)&i + 1) - (char*)&i);
printf("%ld, ", (int*)((int**)&i + 1) - &i);
printf("%ld, ", (int*)((int(*)[5])&i + 1) - &i);
printf("%ld", (int*)((int*(*)[5])&i + 1) - &i);
return 0;
}