what is the output of following question?

void main()
{
int i=0,a[3];
a[i]=i++;
printf("%d",a[i]
}

Answers were Sorted based on User's Feedback



what is the output of following question? void main() { int i=0,a[3]; a[i]=i++; printf("..

Answer / vignesh1988i

my opinion or wat i think is that ,
a[i]=i++; is given so...

here i++ is a post increment operation , so first it will assign the value to a[0]=0 , so a[0] will have 0 , and in next line a[i] is given in printf , so the value a[1] should get printed that will be garbage value.......


thank u

Is This Answer Correct ?    4 Yes 1 No

what is the output of following question? void main() { int i=0,a[3]; a[i]=i++; printf("..

Answer / sha

Vignesh, you are right about the post incerement operation.
The a[i]=a[0] which will be assigned 0 but the printf will
print 0 as output because its printing the a[0] and not a
[1].

Is This Answer Correct ?    0 Yes 0 No

what is the output of following question? void main() { int i=0,a[3]; a[i]=i++; printf("..

Answer / ankur mohan sharma

A garbage value
Explanaiton:-since we have post increment operator applied on i. It's value gets incremented in next statement, so
a[i]=i++ means a[0]= 0
so a[0] is assigned value 0;
and now i becomes 1;
In next statement value of a[i] is to be printed which means value of a[1], which is not initialised. So value printed is a
garbage value.
Remarks
1. An uninitialised variable holds a garbage value.
2. Post increment operator increments value in next line.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); } what is the output?

10 Answers   Ramco,


Explain what math functions are available for integers? For floating point?

0 Answers  


accept character from keyboard untill the user presses the enter key.If the user enters any character other than upper case(A-Z)alphabets program should stop taking any input

1 Answers  


Explain the difference between getch() and getche() in c?

0 Answers  


What is queue in c?

0 Answers  






Write a c program using for loop to print typical pattern if number of rows is entered by keyboard. ABCBA AB BA A A

1 Answers  


is compiler do read the data line by line or not. ??

6 Answers   LG Soft, Satyam, Tech Mahindra,


Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it?

3 Answers  


WAP to accept first name,middle name & last name of a student display its initials?

5 Answers   AITH, NIIT,


What happens if a header file is included twice?

0 Answers  


What is a static function in c?

0 Answers  


in programming languages a statement or part of a statement that specifies several different execution sequences a) constructs b) distructs c) executes d) none

0 Answers  


Categories