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); } 4 12 3 12 compile error run time error Programming in C go-programming-1 programming programming-in-c one-mark + – Arjun 2.3k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 2 2 votes st1.name = "Ram" strln(st1.name) = 3 st1.age = 12 It will print 3 12 Digvijay Pandey answered Oct 20, 2016 • selected Oct 20, 2016 by Arjun Digvijay Pandey comment Share Follow See all 4 Comments 4 4 Comments reply Manoja Rajalakshmi A commented Nov 23, 2017 reply Follow flag what about the format specifiers? u is a specifier meaning "unsigned decimal integer". l is a length modifier meaning "long". 0 0 replyShare Shubhm commented Jul 9, 2019 reply Follow flag can we declare or define structure inside main ? 0 0 replyShare shivam001 commented Jan 2, 2020 reply Follow flag @Digvijay Pandey sir, name is character type ,then strlen should be 4 ??? 1 1 replyShare jay__sadhu commented Dec 26, 2022 reply Follow flag To woh null ki value add nhi krega 0 0 replyShare Please log in or register to add a comment.
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. SHIVAM GARG answered Jul 25, 2018 SHIVAM GARG comment Share Follow See all 3 Comments 3 3 Comments reply Vamshi commented Aug 3, 2018 reply Follow flag why this not take NULL as char....can u explain plzzzzzzzzzzzzzz 0 0 replyShare SHIVAM GARG commented Aug 14, 2018 reply Follow flag null value is calulated by compiler automatically. 0 0 replyShare Lingaraj_G_M commented Nov 22, 2025 reply Follow flag only sizeof() method calcuates the null not strlen 0 0 replyShare Please log in or register to add a comment.