Thursday, 9 February 2012

Frequently Asked Questions in Technical Round at MNCs like TCS, WIPRO, INFOSYS,..etc – 8

Predict the output or error(s) for the following:


1)

int i,j;

for(i=0;i<=10;i++)

{

j+=5;


assert(i<5);


}

Answer:

Runtime error: Abnormal program termination.


assert failed (i<5), <file name>,<line number>


Explanation:

asserts are used during debugging to make sure that certain conditions are satisfied. If assertion fails, the program will terminate reporting the same. After debugging use,


            #undef NDEBUG


and this will disable all the assertions from the source code. Assertion is a good debugging tool to make use of.


2)

main()

{

int i=-1;


+i;


printf("i = %d, +i = %d \n",i,+i);


}

Answer:

 i = -1, +i = -1


Explanation:

Unary + is the only dummy operator in C. Where-ever it comes you can just ignore it just because it has no effect in the expressions (hence the name dummy operator).


3)

What are the files which are automatically opened when a C file is executed?


Answer:

stdin, stdout, stderr (standard input,standard output,standard error).


4)

what will be the position of the file marker?

a: fseek(ptr,0,SEEK_SET);

b: fseek(ptr,0,SEEK_CUR);

Answer :

a: The SEEK_SET sets the file position marker to the starting of the file.


b: The SEEK_CUR sets the file position marker to the current position of the file.

No comments:

Post a Comment