Skip to content
Related Articles

Related Articles

C | String | Question 14
  • Difficulty Level : Basic
  • Last Updated : 12 Sep, 2013

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)

Explanation: Note that the sizeof() operator would return size of array. To get size of string stored in array, we need to use strlen(). The following program prints 9.

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


Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :