Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

C Programming :: Basic Concepts

Home > C Programming > Basic Concepts > General Questions

1. What is the output of the following C Program?

#include
void main()
{
int i;
printf("%d",scanf("%d",&i)); // value 20 is given as input here
}

Answer: 1

Explanation:

Scanf returns number of items successfully read and not 1/0.
Here 10 is given as input which should have been scanned successfully. So number of items read is 1.

Workspace

Tags:

No Tags on this question yet!

2. What is the output of the following C Program?

#include
void main(){
int i;
for(i=0;i<5;i++){
int x=0;
printf("%d",x);
x++;
}
}

Answer: 0

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

3. What is the output of the following C Program?

#include
void main()
{
main();
}

Answer: Stack overflow.

Explanation:

main function calls itself again and again. Each time the function is called its return address is stored in the call stack.
Since there is no condition to terminate the function call, the call stack overflows at runtime. So it terminates the program and results in an error.

Workspace

Tags:

No Tags on this question yet!

4. What is the output of the following C Program?

#include
int main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
return 0;
}

Answer: hai

Explanation:

\n - newline

\b - backspace

\r - linefeed

Workspace

Tags:

No Tags on this question yet!

5. What is the output of the following C Program?

#include
void main(){
int z;
z=(5,3,2);
printf("%d",z);
}

Answer: 2

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

6. What is the output of the following C Program?

#include
void main()
{
clrscr();
}
clrscr();

Answer: No output/error

Explanation:

The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function).

Workspace

Tags:

No Tags on this question yet!

7. What is the output of the following C Program?

#include
void main()
{
char not;
not=!2;
printf("%d",not);
}

Answer: 0

Explanation:

! is a logical operator. In C the value 0 is considered to be the boolean value FALSE, and any non-zero value is considered to be the boolean value TRUE. Here 2 is a non-zero value so TRUE. !TRUE is FALSE (0) so it prints
0.

Workspace

Tags:

No Tags on this question yet!

8. What is the output of the following C Program?

#include
void main()
{
int y;
scanf("%d",&y); // Given Input is 2000
if( (y%4==0 && y%100 != 0) || y%100 == 0 )
printf("%d is a leap year");
else
printf("%d is not a leap year");
}

Answer: 2000 is a leap year

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

9. What is the output of the following C Program?

#include
int main()
{
int c=- -2;
printf("c=%d",c);
return 0;
}

Answer: c=2

Explanation:

Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus= plus.
Note:
However you cannot give like --2. Because -- operator can only be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.

Workspace

Tags:

No Tags on this question yet!

10. What will be the output of the below C program.

#include
void main()
{
int i=400,j=300;
printf("%d..%d");
}

Answer: Garbage Value

Explanation:

printf takes the values of the first two assignments of the program. Any number of printf's may be given. All of them take only the first two values. If more number of assignments given in the program,then printf will take garbage values.

Workspace

Tags:

No Tags on this question yet!