C Programming :: Basic Concepts

Home > C Programming > Basic Concepts > General Questions

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

1 / 65

 What is the output of the following C Program?

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

ACompiler error

BStack overflow.

CNone of these

Answer: Option B

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

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

2 / 65

 What is the output of the following C Program?

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

ANo output/error

BCompilation Error

CNone of these

Answer: Option A

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

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

3 / 65

 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");
}

A2000 is not a leap year

B2000 is a leap year

CCompilation Error

DNone of these

Answer: Option B

Explanation:

It is just a simple leap year program , when if condition is evaluated it returns true value. So, "2000 is a leap year" get printed.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

4 / 65

 What will be the output of the below C program.

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

AGarbage Value

B400..300

CCompilation error

DNone of these

Answer: Option A

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

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

5 / 65

 What will be the output of the below C program.

#include
int main()
{
printf("%d", out);
return 0;
}
int out=100;

ACompiler error: undefined symbol out in function main.

B100

C10

DNone of these

Answer: Option A

Explanation:

The rule is that a variable is available for use from the point of declaration. Even though a is a global variable, it is not available for main. Hence an error.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

6 / 65

 What will be the output of the below C program.

#include
int main()
{
extern int i; i=20;
printf("%d",sizeof(i));
return 0;
}

ACompilation error: undefined reference to `i'

BLinker error: undefined reference to `i'

C20

DNone of these

Answer: Option B

Explanation:

extern declaration specifies that the variable i is defined somewhere else. The compiler passes the external variable to be resolved by the linker. So compiler doesn't find an error. During linking the linker searches for the definition of i. Since it is not found the linker flags an error.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

7 / 65

 What will be the output of the below C program.

#include
int main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
return 0;
}

ACompilation Error

Bi=-1, +i=0

Ci = -1, +i = -1

DNone of these

Answer: Option C

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).

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

8 / 65

 What will be the output of the below C program.

#include
int main()
{
int i=-1;
-i;
printf("i = %d, -i = %d \n",i,-i);
return 0;
}

Ai = -1, -i = 1

Bi = 1, -i = 1

Ci = -1, -i = -1

DComilation error

ENone of these

Answer: Option A

Explanation:

-i is executed and this execution doesn't affect the value of i. In printf first you just print the value of i.
After that the value of the expression -i = -(-1) is printed.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

9 / 65

 What will be the output of the below C program.

#include
int main()
{
int k=1;
printf("%d==1 is %s",k,k==1?"TRUE":"FALSE");
return 0;
}

A1==1 is TRUE

B1==1 is FALSE

CCompilation error

DNone of these

Answer: Option A

Explanation:

When two strings are placed together (or separated by white-space) they are concatenated (this is called as "stringization" operation). So the string is as if it is given as "%d==1 is %s". The conditional operator( ?: ) evaluates to "TRUE".

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

10 / 65

 What will be the output of the below C program.

#include
int main(){
int a= 0;
int b = 20;
char x =1;
char y =10;
if(a,b,x,y)
printf("hello");
return 0;
}

Ahello

BCompilation Error

Cno output No Error

DNone of these

Answer: Option A

Explanation:

The comma operator has associativity from left to right. Only the rightmost value is returned and the other values are evaluated and ignored.
Thus the value of last variable y is returned to check in if. Since it is a non zero value if becomes true so, "hello" will be printed.

Workspace