Question 1
i) sizeof(int);
ii) sizeof(int*);
iii) sizeof(int**);
Question 2
char *pChar;
int *pInt;
float *pFloat;
sizeof(pChar);
sizeof(pInt);
sizeof(pFloat);
Question 3
#include <stdlib.h>
int main()
{
int *pInt;
int **ppInt1;
int **ppInt2;
pInt = (int*)malloc(sizeof(int));
ppInt1 = (int**)malloc(10*sizeof(int*));
ppInt2 = (int**)malloc(10*sizeof(int*));
free(pInt);
free(ppInt1);
free(*ppInt2);
return 0;
}
Choose the correct statement w.r.t. above C program.
malloc() for ppInt1 and ppInt2 isn’t correct. It’ll give compile time error.
free(*ppInt2) is not correct. It’ll give compile time error.
free(*ppInt2) is not correct. It’ll give run time error.
No issue with any of the malloc() and free() i.e. no compile/run time error.
Question 4
#include <stdio.h>
int main()
{
void *pVoid;
pVoid = (void*)0;
printf("%lu",sizeof(pVoid));
return 0;
}
Pick the best statement for the above C program snippet.
Assigning (void *)0 to pVoid isn’t correct because memory hasn’t been allocated. That’s why no compile error but it'll result in run time error.
Assigning (void *)0 to pVoid isn’t correct because a hard coded value (here zero i.e. 0) can’t assigned to any pointer. That’s why it'll result in compile error.
No compile issue and no run time issue. And the size of the void pointer i.e. pVoid would equal to size of int.
sizeof() operator isn’t defined for a pointer of void type.
Question 5
i) int var_9 = 1;
ii) int 9_var = 2;
iii) int _ = 3;
Question 6
Let x be an integer which can take a value of 0 or 1. The statement if(x = =0) x = 1; else x = 0; is equivalent to which one of the following?
x = 1 + x;
x = 1 - x;
x = x - 1;
x = 1 % x;
Question 7
A program attempts to generate as many permutations as possible of the string, 'abcd' by pushing the characters a, b, c, d in the same order onto a stack, but it may pop off the top character at any time. Which one of the following strings CANNOT be generated using this program?
abcd
dcba
cbad
cabd
Question 8
int main()
{
int (*ptr)(int ) = fun;
(*ptr)(3);
return 0;
}
int fun(int n)
{
for(;n > 0; n--)
printf("GeeksQuiz ");
return 0;
}
int main()
{
void demo();
void (*fun)();
fun = demo;
(*fun)();
fun();
return 0;
}
void demo()
{
printf("GeeksQuiz ");
}
Question 9
/*Program Snippet 1 with for loop*/
for (i = 0; i < 10; i++)
{
/*statement1*/
continue;
/*statement2*/
}
/*Program Snippet 2 with while loop*/
i = 0;
while (i < 10)
{
/*statement1*/
continue;
/*statement2*/
i++;
}
/*Program Snippet 3 with do-while loop*/
i = 0;
do
{
/*statement1*/
continue;
/*statement2*/
i++;
}while (i < 10);
After hitting the continue; statement in all the loops, the next expression to be executed would be controlling expression (i.e. i < 10) in all the 3 loops.
There are 9 questions to complete.