What is the output of the code given below?
#include <stdio.h> int main( )
{
char name[ ]=“satellites”;
int len;
int size;
len = strlen (name);
size = sizeof (name);
printf (“%d”, len * size);
return 0;
}
|
(A) 100
(B) 110
(C) 40
(D) 44
Answer: (B)
Explanation: Note –
- strlen() function returns length of string without null character.
- sizeof() function returns size of string with null character.
- sizeof() = strlen() + 1
Therefore, 110 will be printed.
#include <stdio.h> #include <cstring> int main( )
{
char name[ ]= "satellites" ;
int len;
int size;
len = strlen (name);
size = sizeof (name);
printf ( "%d" , len * size);
return 0;
}
|
Option (B) is correct.
Quiz of this Question
Article Tags :
Recommended Articles