Monday, December 1, 2008

Simple C Language placement Question and answer

96) void main()
{
static int i=5;
if(--i)
{
main();
printf("%d ",i);
}
}

Answer:-
 0 0 0 0

Explanation:
The variable "I" is declared as static, hence memory for I will be allocated for only once, as it encounters the statement. The function main() will be called recursively unless I becomes equal to 0, and since main() is recursively called, so the value of static I ie., 0 will be printed every time the control is returned.

2)
void main()
{
int k=ret(sizeof(float));
printf("\n here value is %d",++k);
}
int ret(int ret)
{
ret += 2.5;
return(ret);
}


Answer:-
 Here value is 7

Explanation:
The int ret(int ret), ie., the function name and the argument name can be the same.
Firstly, the function ret() is called in which the sizeof(float) ie., 4 is passed,  after the first expression the value in ret will be 6, as ret is integer hence the value stored in ret will have implicit type conversion from float to int. The ret is returned in main() it is printed after and preincrement.
 
3)
void main()
{
char a[]="12345\0";
int i=strlen(a);
printf("here in 3 %d\n",++i);
}

Answer: 
here in 3 6

Explanation:
The char array 'a' will hold the initialized string, whose length will be counted from 0 till the null character. Hence the 'I' will hold the value equal to 5, after the pre-increment in the printf statement, the 6 will be printed.
4)
void main()
{
unsigned giveit=-1;
int gotit;
printf("%u ",++giveit);
printf("%u \n",gotit=--giveit);
}

Answer:
 0 65535

5)
void main()
{
int i;
char a[ ]="\0";
if(printf("%s\n",a))
printf("Ok here \n");
else
printf("Forget it\n");
}

Answer:-
 Ok here 

Explanation:
Printf will return how many characters does it print. Hence printing a null character returns 1 which makes the if statement true, thus "Ok here" is printed.

ALL PLACEMENT TECHNICAL INTERVIEW QUESTION  BANCK   

1Technical /logical interview questions and solution in C language |2Technical / logical interview questions in C language |3C programming Language Technical Questions And Answers |4C Language Technical Questions And Answers |5C Language Technical Interview Questions And solution |6C Language Technical Interview Questions And Answers |7C Language Interview Questions And Solution |8online Placement Question of c programming languge |9online placement c programming question|10online test of c programming languge|11placement c programming quiz with solution |12c programming quiz with solution |13C programming languge quiz with solution |14C quiz with solution |15C languge quiz with solution  |16C programming quiz with solution |17questions with answer in C programming language|18Technical questions with solution in C programming language  |19Technical questions with answer in C programming language |20placement Question and answer in Simple C Language |21Simple C Language placement Question and answer22Simple C programming Question and answer |23Simple C programming Question and answer |24Simple C Language Question and answer |25c progrmming Interview question with solution  |26Technical placement question with solution in c progrmming |27placement c progrmming Question with Answer  |28c progrmming placement question with solution  |29 placement c progrmming languge question with Answer |30placement c progrmming languge question with solution  |31c progrmming languge placement question with solution  |32c languge placement question with solution |33placement c programming languge problem with solution  |34c programming languge placement problem with solution  |35c language placement problem with solution  |36Placement c languge problem with solution  |37c language problem with answer  |38c language problem with solution  |

No comments:

Post a Comment

Thanks to given comments.......

My Blog List