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 does the following statement mean? int (*a)[4]

824


What is searching? Explain linear and binary search.

790


What is a list c++?

833


Describe linkages and types of linkages?

773


What's the order in which the local objects are destructed?

1018


What is stoi in c++?

921


Should you pass exceptions by value or by reference?

913


Why c++ is faster than java?

821


How does atoi function work?

874


Describe new operator and delete operator?

845


If a function doesn’t return a value, how do you declare the function?

816


Can we make copy constructor private in c++?

817


What do you mean by public protected and private in c++?

790


Explain the difference between new() and malloc() in c++?

851


Is map sorted c++?

741