2,258 views
5 5 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 2 votes
st1.name = "Ram"
strln(st1.name) = 3

st1.age = 12

It will print 3 12
• selected by
0 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:
Position:
Show:

Related questions

6 6 votes
1 1 answer
3.3k
3.3k views
Arjun asked Oct 18, 2016
3,287 views
Consider the following incomplete C function for reversing a singly linked list.node* reverse(node* trav){ if(trav->next) __________________ else { head - next = null; he...
9 9 votes
2 answers 2 answers
2.4k
2.4k views
Arjun asked Oct 18, 2016
2,397 views
int foo(int n) { if(n 10000) return 1; int sum = 0, i; for( i = 0; i < n; i++) { sum += i; } return sum; }The value returned by the above function is$\Theta\left(n^2\rig...
1 1 vote
4 4 answers
5.3k
5.3k views
Arjun asked Oct 18, 2016
5,330 views
Which of the following statements is true regarding C language?S1: C is a functional languageS2: C is a declarative languageS3: C is a procedural languageS4: C is a struc...
3 3 votes
4 answers 4 answers
1.6k
1.6k views
Arjun asked Oct 18, 2016
1,629 views
What will be the output of the following code?#include <stdio.h int main() { char a = 'A', z = 'Z'; printf("%d", z-a); }