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
Does c++ have string data type?
Describe the advantages of operator overloading?
What are single and multiple inheritances in c++?
Array base access faster or pointer base access is faster?
List the issue that the auto_ptr object handles?
Will a catch statement catch a derived exception if it is looking for the base class?
What are c++ stream classes?
What is the syntax for a for loop?
What does the nocreate and noreplace flag ensure when they are used for opening a file?
What is the output of the following program? Why?
How do you remove an element from a set in c++?
If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?
Why is it necessary to use a reference in the argument to the copy constructor?
What is the v-ptr?
What is the fastest c++ compiler?