488 views
1 votes
1 votes

What is output of the program?? And why??

1 Answer

1 votes
1 votes
O/P

1. puts(a);//passes base adress of array a to puts fn which try to print untill it find '\0' which never occur

So here o/p of this statement is :- abc then appended with some garbage character.

2. sizeof(&a[0]);

Explanation:- &a[0] gives base adress of String  constant "abc" and it considers the '\0' char @ end of the string constant by default ..So here o/p is 4

Note:- if Here we only Changes a[50]="abc" also the o/p of above sizeof statement is 4 only bcz it deal with the string constant size.

But if we are writing sizeof(a) then it return 50 for a[50] and 3 for given question.

Related questions

6 votes
6 votes
3 answers
1
papesh asked Aug 15, 2016
587 views
int i; i=5; i=i++; printf("%d",i);What is output of this program??Is it undefined behavior ?? Why??
1 votes
1 votes
2 answers
2
papesh asked Aug 11, 2016
415 views
Suppose in my c program having infinite loop and it is printing garbase values ... Because of some logical errors... So till what time it will run and why ??? Will it giv...