Open In App

ISRO | ISRO CS 2020 | Question 36

Like Article
Like
Save
Share
Report

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


Last Updated : 04 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads