VOOZH about

URL: https://www.geeksforgeeks.org/quizzes/c-quiz-101-gq/

⇱ Quiz about C Quiz - 101


Last Updated :
Discuss
Comments

Question 1

Suppose that in a C program snippet, followings statements are used. Assuming size of pointer is 4 bytes and size of int is also 4 bytes, pick the most correct answer from the given options.
  • Only i) would compile successfully and it would return size as 4.
  • i), ii) and iii) would compile successfully and size of each would be same i.e. 4
  • i), ii) and iii) would compile successfully but the size of each would be different and would be decided at run time.
  • ii) and iii) would result in compile error but i) would compile and result in size as 4.

Question 2

Assume int is 4 bytes, char is 1 byte and float is 4 bytes. Also, assume that pointer size is 4 bytes (i.e. typical case) What’s the size returned for each of sizeof() operator?
  • 4 4 4
  • 1 4 4
  • 1 4 8
  • None of the above

Question 3

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

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

Consider the following variable declarations and definitions in C

Choose the correct statement w.r.t. above variables.

  • Both i) and iii) are valid.

  • Only i) is valid.

  • Both i) and ii) are valid.

  • All are valid.

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

Consider following two C - program :
P1 : P2 : Which of the following option is correct?
  • P1 printed "GeeksQuiz GeeksQuiz" and P2 printed "GeeksQuiz GeeksQuiz"
  • P1 printed "GeeksQuiz GeeksQuiz" and P2 gives compiler error
  • P1 gives compiler error and P2 printed "GeeksQuiz GeeksQuiz"
  • None of the above

Question 9

Choose the best statement with respect to following three program snippets.
  • All the loops are equivalent i.e. any of the three can be chosen and they all will perform exactly same.
  • continue can\'t be used with all the three loops in C.
  • 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.

  • None of the above is correct.
Tags:

There are 9 questions to complete.

Take a part in the ongoing discussion