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 literals in C++?
How can you create a virtual copy constructor?
What is the best c++ ide?
What is polymorphism & list its types in c++?
Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?
How is data hiding achieved in c++?
Write about an iterator class?
Describe Trees using C++ with an example.
How do you clear a buffer in c++?
What is data type in c++?
What is ifstream c++?
What is the difference between a type-specific template friend class and a general template friend class?
What is meant by entry controlled loop?
Why use of template is better than a base class?
What is the maximum combined length of command line arguments including the space between adjacent arguments?