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

Does std endl flush?

613


How do I exit turbo c++?

590


What are the different types of comments allowed in c++?

583


What is abstraction c++?

597


Does dev c++ support c++ 11?

565






What can c++ be used for?

591


Differentiate between an external iterator and an internal iterator? What is the advantage of an external iterator.

625


How to declare an array of pointers to integer?

591


Can we delete this pointer in c++?

689


What is c++ iterator?

651


Write a program in c++ to print the numbers from n to n2 except 5 and its multiples

2047


What is a c++ class?

631


How do you flush a buffer in c++?

612


How does the copy constructor differ from the assignment operator (=)?

631


What is #include iostream h in c++?

628