what is the output of following question?

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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

When would you use a pointer to a function?

591


How can a program be made to print the name of a source file where an error occurs?

735


What is the difference between the expression “++a” and “a++”?

652


Is fortran still used today?

609


How can you invoke another program from within a C program?

620






Explain how do I determine whether a character is numeric, alphabetic, and so on?

658


What is scope of variable in c?

573


How can a program be made to print the line number where an error occurs?

656


 write a program that will open the file, count the number of occurences of each word in the the complete works of shakespeare.  You will then tabulate this information in another file.

1732


What is class and object in c?

592


What are formal parameters?

664


Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1

3663


What is the use of ?: Operator?

671


how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12

658


Explain data types & how many data types supported by c?

588