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 are the new features that iso/ansi c++ has added to original c++ specifications?

834


What is a singleton c++?

800


What is polymorphism & list its types in c++?

824


How can you quickly find the number of elements stored in a static array?

870


Do you know the use of vtable?

882


What is a memory leak c++?

802


What is the use of volatile variable?

860


Can a built-in function be recursive?

808


Explain the differences between private, public and protected and give examples.

796


the first character in the variable name must be an a) special symbol b) number c) alphabet

858


How is new() different from malloc()?

870


Distinguish between new and malloc and delete and free().

790


What are the advantage of using register variables?

872


Explain virtual class and friend class.

817


What c++ is used for?

861