in Programming
702 views
2 votes
2 votes

What will be the output of the following code?

#include <stdio.h>
#include <string.h>
int main()
{
    struct mystruct{
        char *name;
        unsigned int age;
    };
    struct mystruct st1 = {"Ram", 12};
    printf("%lu %u", strlen(st1.name), st1.age);
}
  1. 4 12
  2. 3 12
  3. compile error
  4. run time error
in Programming
by
702 views

2 Answers

2 votes
2 votes
Best answer
st1.name = "Ram"
strln(st1.name) = 3

st1.age = 12

It will print 3 12
selected by

3 Comments

what about the format specifiers? 

u is a specifier meaning "unsigned decimal integer".

l is a length modifier meaning "long".

0
0
can we declare or define structure inside main ?
0
0

@Digvijay Pandey sir, name is character type ,then strlen should be 4 ???

 

0
0
0 votes
0 votes
str1="Ram",12

str1.name =Ram

str1.age=12

strlen(Ram)=3

so 3 12  will be printed

option(B) is correct

it will not calculated NULL as a character.

2 Comments

why this not take NULL as char....can u explain plzzzzzzzzzzzzzz
0
0
null value is calulated by compiler automatically.
0
0
Answer:

Related questions