int main()
{
int i ,a[i];
i = 0;
a[i] = 10;
cout<< a[i] << endl;
return 0;


}

What will be output of this program?

Answer Posted / rajesh

It will give segmentation fault(core dumped) - runtime error

This is not the way of declaring an array...a slight change
in program can correct it. Code below...

int main()
{
int i=0 ,a[i];
// i = 0;
a[i] = 10;
cout<< a[i] << endl;
return 0;
}
output : 10

please initialise the value of i before putting it in array
a[i]..this code will work fine and will give the output as 10.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is c++ programming language?

565


What are vectors used for in c++?

613


What are different types of loops in c++?

644


What is a block in c++?

542


What is a vector c++?

545






When must you use a pointer rather than a reference?

596


Can manipulators fall in love?

557


Explain the use of vtable.

611


What problems might the following macro bring to the application?

609


If dog is a friend of boy, and terrier derives from dog, is terrier a friend of boy?

604


What are the operators in c++?

584


Do you know what are static and dynamic type checking?

612


Describe the syntax of single inheritance in C++?

637


Explain the difference between struct and class in terms of access modifier.

689


If a header file is included twice by mistake in the program, will it give any error?

543