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 3 levels of programming languages?
How do I run a program in notepad ++?
What is static function? Explain with an example
Why do we need templates?
What is a container class? What are the types of container classes in c++?
When there is a global variable and local variable with the same name, how will you access the global variable?
Can you please explain the difference between using macro and inline functions?
Can we make copy constructor private in c++?
Define the process of error-handling in case of constructor failure?
Is c++ a float?
What do you understand by pure virtual function? Write about its use?
Write a program using display() function which takes two arguments.
Differentiate between a copy constructor and an overloaded assignment operator.
What is object oriented programming (oop)?
How would you use the functions randomize() and random()?