Exercise: Questions on C Quiz 6


Questions on C Quiz 6 : Question 1 :
Assuming int size is 4 bytes, what is going to happen when we compile and run the following program?
 #include 
 int main()
 {
   printf("PROcoder\n");
   main();
   return 0;
 }
 

We can't use main() inside main() and compiler will catch it by showing compiler error.
PROcoder would be printed in 2147483647 times i.e. (2 to the power 31) - 1.
It'll print PROcoder infinite times i.e. the program will continue to run forever until it's terminated by other means such as CTRL+C or CTRL+Z etc.
No compile error but behaviour of the program would depend on C compiler due to nondeterministic behaviour of goto statement.
PROcoder would be printed until stack overflow happens for this program.
Show Answer
Questions on C Quiz 6 : Question 2 :
What’s the meaning of following declaration in C language?
int (*p)[5];

It will result in compile error because there shouldn't be any parenthesis i.e. “int *p[5]” is valid.
p is a pointer to 5 integers.
p is a pointer to integer array.
p is an array of 5 pointers to integers.
p is a pointer to an array of 5 integers
Show Answer
Questions on C Quiz 6 : Question 3 :
In a C program, following variables are defined:
 float      x = 2.17;
 double   y = 2.17;
 long double z = 2.17;
Which of the following is correct way for printing these variables via printf.

printf("%f %lf %Lf",x,y,z);
printf(“%f %f %f”,x,y,z);
printf("%f %ff %fff",x,y,z);
printf("%f %lf %llf",x,y,z);
Show Answer
Questions on C Quiz 6 : Question 4 :
“typedef” in C basically works as an alias. Which of the following is correct for “typedef”?

typedef can be used to alias compound data types such as struct and union.
typedef can be used to alias both compound data types and pointer to these compound types.
typedef can be used to alias a function pointer.
typedef can be used to alias an array.
All of the above.
Show Answer
Questions on C Quiz 6 : Question 5 :
For the following “typedef” in C, pick the best statement
typedef int INT, *INTPTR, ONEDARR[10], TWODARR[10][10];

It will cause compile error because typedef is being used to define multiple aliases of incompatible types in the same statement.
“INT x” would define x of type int. Remaining part of the statement would be ignored.
“INT x” would define x of type int and “INTPTR y” would define pointer y of type int *. Remaining part of the statement would be ignored.
“INT x” would define x of type int. “INTPTR y” would define pointer y of type int *. ONEDARR is an array of 10 int. TWODARR is a 2D array of 10 by 10 int.
“INT x” would define x of type int. “INTPTR *y” would define pointer y of type int **. “ONEDARR z” would define z as array of 10 int. “TWODARR t” would define t as array of 10 by 10 int.
Show Answer