1,060 views
3 votes
3 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

2 Answers

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

st1.age = 12

It will print 3 12
selected by
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.
Answer:

Related questions

8 votes
8 votes
2 answers
2
1 votes
1 votes
3 answers
3
3 votes
3 votes
4 answers
4
Arjun asked Oct 18, 2016
775 views
What will be the output of the following code?#include <stdio.h int main() { char a = 'A', z = 'Z'; printf("%d", z-a); }