Machine-translated by Google. Questions are authored in English.
Top

Discussion

Assume that a character takes 1 byte. Output of following program?

#include <stdio.h> 
int main() 
{ 
    char str[20] = "GeeksQuiz"; 
    printf ("%d", sizeof(str)); 
    return 0; 
} 

 

  • A.9
  • B.10
  • C.20
  • D.Garbage Value

Answer: C

Correct answer: 20

sizeof reports the size of the array as declared, not the length of the string in it. The array was given 20 elements, so the answer is 20, of which the first ten hold "GeeksQuiz" and its null and the remaining ten are zero-filled. strlen(str) would give 9.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.