C | String | Question 15

Predict the output of following program, assume that a character takes 1 byte and pointer takes 4 bytes.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(A) sizeof(str1) = 10, sizeof(str2) = 10

(B) sizeof(str1) = 4, sizeof(str2) = 10
(C) sizeof(str1) = 4, sizeof(str2) = 4
(D) sizeof(str1) = 10, sizeof(str2) = 4


Answer: (B)

Explanation: str1 is a pointer and str2 is an array.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.