C | String | Question 14
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; } |
chevron_right
filter_none
(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;
}
Recommended Posts:
- C | String | Question 7
- C | String | Question 5
- C | String | Question 6
- C | String | Question 16
- C | String | Question 8
- C | String | Question 9
- C | String | Question 15
- C | String | Question 12
- C | String | Question 13
- C | String | Question 11
- C | String | Question 10
- C | String | Question 1
- C | String | Question 4
- C | String | Question 2
- C | String | Question 3



