User talk:Tiwari.sachin

C Examples
--Tiwari.sachin (talk) 11:32, 28 October 2008 (UTC)

I present a few of the example code that might be helpful for many people to crack their competitive exams

This page contains wide variety of questions and answers, that might sometimes seems crazy to use while other times it might be very useful... There isnt any chapterwise pattern being followed. Any different sort of C questions i come across, i post it here...

Lets start....

1. whats the output for the following code int i=1, j, count; for(j=0; j<=10; j++) {    if(i&j) count++; }  printf("count=%d", count);

Ans: 5, i&j will be true only when LSB is one. This means count will be incremented only for odd numbers. In short this code will print the total number of odd numbers present between 0 and 10.

2. what is the output of the following code i=4; printf("%d", (printf("%d %d %d", ++i, i++, ++i));

Ans: 5 5 7 5, This is because whenever you give any expressions within the printf parameter range, the execution will be from right to left. ++i prints 5 because its pre-increment, i++ prints 5 again because its post-increment, 7 because post- increment of i++ gets added to pre-increment of first ++i, and finally 5 because the printf function withing printf statement returns number of characters it prints on screen which in this case is 5 including spaces.

3. what is the output of the following code i,j,k; printf("%d", (scanf("%d %d %d", &i, &j, &k));

Ans 3, Because scanf is a function that returns number of values that it inputs which in this case is 3.