int main()
{
int i ,a[i];
i = 0;
a[i] = 10;
cout<< a[i] << endl;
return 0;


}

What will be output of this program?

Answers were Sorted based on User's Feedback



int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / sachinmundhra

This will not get compile.

int i , a[i] ; // This statement will given error. Constant
expression required.

Is This Answer Correct ?    38 Yes 3 No

int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / kamal

10

Is This Answer Correct ?    30 Yes 9 No

int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / ravinder kumar(omnietysolution

Error in program

Is This Answer Correct ?    10 Yes 3 No

int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / ramesh kumar

in array we can must enter size integer...
not as variable type like i
thats why it gives an error

Is This Answer Correct ?    9 Yes 2 No

int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / mohammed afroz

There are compile time error in this program. Because array
can declare with a constant value.

Is This Answer Correct ?    7 Yes 2 No

int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / vikas

Index variable of any array should be integer constant.
but in this case i is not constant so it is a error

Is This Answer Correct ?    5 Yes 1 No

int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / ramez

Constant expression will be required here...

Is This Answer Correct ?    4 Yes 1 No

int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / 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

int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / blacky

Compiler will Core Dump

Is This Answer Correct ?    2 Yes 2 No

int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } ..

Answer / anil hooda

it will return any integer value.....

Is This Answer Correct ?    1 Yes 9 No

Post New Answer

More C++ General Interview Questions

Write my own zero-argument manipulator that should work same as hex?

0 Answers  


What is flush programming?

0 Answers  


What is called array?

0 Answers  


When should I use unitbuf flag?

0 Answers  


How can I learn c++ easily?

0 Answers  






What is the full form of dos?

0 Answers  


Can we make any program in c++ without using any header file and what is the shortest program in c++.

0 Answers   MCN Solutions,


What C++ libraries are you proficient with?

1 Answers   Google,


Mention the purpose of istream class?

0 Answers  


Write a program which uses Command Line Arguments

0 Answers  


Can class objects be passed as function arguments?

0 Answers   HCL,


Board Coloring Problem Description In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color. Fill the other elements in the board, such that none of the adjacent elements (vertically, horizontally and diagonally) should be of the same color. Find out the minimum number of colors that should be used to fill the blank spaces in the board, so that the above condition is met. Color representation is -: 0, 1, 2, 3, 4, 5, 6, 7……………………. There is sample board: For Example: Given Board : Matrix representation of board is : [ _ 1 _ _ ] [ 2 _ _ _ ] [ _ _ 2 _ ] [ 2 _ _ _ ] here blank space is represented by '_' . Minimum colors to fill this board (given in the picture)is 4. Instruction to work with Open PBT Client: Specify the work directory path in the 'Work directory Path' field. The path should correspond to your solution Work directory. Download the support files by clicking the Get Dev Files. You will find the problem directories containing: problem.h file problem.c file in your project directory. Code the solution in.c file inside the problem directory All required files will be downloaded to your work directory. Creating additional files is strongly discouraged. Step 1: In your Solution File: Implement your logic in function int color(char board[4][4]) char board[4][4]board is 2 dimensional matrix of order M X M where M = 4. You can create more functions if required, but those functions should be in the same file. Step 2: In your solution keep in mind the following constraints. In this problem you have to write a program that finds the minimum number of colors needed to fill a board in which some of the elements are placed in advance. Function color() will take 2 dimension board as a input. Function color() returns the minimum number of colors that could fill the board meeting the given condition. Board is a 2 dimensional of M X M where M = 4 else return 0 Fill the other elements in the board, such that none of the adjacent elements (vertically, horizontally and diagonally) should be of the same color. The Prototype of the function is int color(char board[4][4]) This function takes following arguments. board is 2 dimensional matrix of order M X M where M = 4. This function returns minimum no of color by which board can be filled. The constraints are: Board is a 2 dimensional of M X M where M = 4 else return 0 Fill the other elements in the board, such that none of the adjacent elements (vertically, horizontally and diagonally) should be of the same color. Example 1 Input { 2 0 _ 1 } { _ 1 _ _ } { _ 2 _ 0 } { _ _ _ 1 } Output 5 Explanation: We need a minimum 5 different colors to complete the board. Example 2 Input { 2 0 _ 1 3} { _ 1 _ _ 2} { _ 2 _ 0 1} { _ _ _ 1 2} { _ _ _ _ 0} Output 0 Explanation: Size of the board is greater than 4X4. Example 3 Input { _ 0 } { 1 _ } Output 0 Explanation: Size of the board is less than 4X4. For C solutions Header File : boardcoloring.h Function Name : int color(char board1[4][4]) File Name : boardcoloring.c For C++ solutions Header File : boardcoloring.h Class Name : BoardColoring Function Name : int color(char board1[4][4]) File Name : boardcoloring.c

0 Answers   Infosys,


Categories