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
What are the new features that iso/ansi c++ has added to original c++ specifications?
What is a singleton c++?
What is polymorphism & list its types in c++?
How can you quickly find the number of elements stored in a static array?
Do you know the use of vtable?
What is a memory leak c++?
What is the use of volatile variable?
Can a built-in function be recursive?
Explain the differences between private, public and protected and give examples.
the first character in the variable name must be an a) special symbol b) number c) alphabet
How is new() different from malloc()?
Distinguish between new and malloc and delete and free().
What are the advantage of using register variables?
Explain virtual class and friend class.
What c++ is used for?