ExamVeda
Login
Home
31
What is the output of given program if user enter value 99?
#include<stdio.h>
void main()
{
	int i;
	printf("Enter a number:");
	scanf("%d", &i); // 99 is given as input.
	if(i%5 == 0){
		printf("nNumber entered is divisible by 5");
        }
}
Discuss
Answer & Solution
Answer: Option A
Solution:

since this program isn't having any syntax error so program is executed. It is clearly seen that 99 is not divisible by 5. So if statement will not execute and program will terminate.

32
What is the output of given program if user enter "xyz" ?
#include<stdio.h>
void main()
{
	float age, AgeInSeconds;
	printf("Enter your age:");
	scanf("%f", &age);
	AgeInSeconds = 365 * 24 * 60 * 60 * age;
	printf("You have lived for %f seconds", AgeInSeconds);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

When we give scanf() a "%f" format string, that means "We want you to try and get us a floating point number. When we provide input like 'xyz', it's not going to match anything, because 'xyz' is not a valid floating-point number.

33
What is the output of given program if user enter "xyz" ?
#include<stdio.h>
void main()
{
	float age, AgeInSeconds;
	int value;
	printf("Enter your age:");
	value=scanf("%f", &age);
	if(value==0){
		printf("\\nYour age is not valid");
	}
	AgeInSeconds = 365 * 24 * 60 * 60 * age;
	printf("\\n You have lived for %f seconds", AgeInSeconds);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

When we give scanf() a "%f" format string, that means "We want you to try and get us a floating point number. When we provide input like 'xyz', it's not going to match anything, because 'xyz' is not a valid floating-point number.

34
What will be the output of the given program?
#include<stdio.h>
void main()
{
      int  i=10;
      printf("i=%d", i);
      {
            int  i=20;
	    printf("i=%d", i);
	    i++;
	    printf("i=%d", i);
      }
      printf("i=%d", i);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

The scope of second declaration of i is limited to the block in which it is defined. Outside of the block variable is not recognized.

35
What will be the value of i and j after execution of following program?
#include<stdio.h>
void main()
{
	int i, j;
	for(i=0,j=0;i<10,j<20;i++,j++){
		printf("i=%d %t j=%d", i, j);
       }
}
Discuss
Answer & Solution
Answer: Option C
Solution:

comma operator is executed from left to right so until j<20 for loop statement is true, so both i and j are incremented.
So, i = 20 and j = 20.

36
What will be the output given program?
#include<stdio.h>
void main()
{
	int i = -10;
	for(;i;printf("%d ", i++));
}
Discuss
Answer & Solution
Answer: Option A
Solution:

for loop can be initialized outside of the loop. Since until -1 value of i remain a non-zero value and hence the condition is true up to -1. But when i is further increases its value becomes 0 and condition becomes false and loop stops there.

Note:In C any non-zero value(positive or negative) evaluates to true and only zero value is evaluates to false.

37
What will be the output of the given program?
#include<stdio.h>
void main()
{
	int a=11,b=5;
	if(a=5) b++;
	printf("%d %d", ++a, b++);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Here if condition evaluates to true as a non-zero value i.e 5 is assigned to a.
So the value of a = 5 and after increment value of b = 6.
In printf statement due to pre-increment of a value of a printed will be 6 and due to post-increment of b value of b printed will be 6 and not 7.

38
What will be the output of the given program?
#include<stdio.h>
void main()
{
      int value=0;
      if(value)
            printf("well done ");
      printf("examveda");
}
Discuss
Answer & Solution
Answer: Option B
Solution:

As the value of variable value is zero so, it evaluates to false in the if condition.

39
What will be the output of the given program?
#include<stdio.h>
void main()
{
	int value1, value2=100, num=100;
	if(value1=value2%5) num=5;
	printf("%d %d %d", num, value1, value2);
}
Discuss
Answer & Solution
Answer: Option D
Solution:

Expression value2%5 is equal to 0 and this value assigned to value1.
Therefore if condition reduces to if(0) so it fails.
Therefore body of if will not be executed i.e num = 5 will not be assigned.
So at printf num = 100 , value1 = 0 and value2 = 100.

40
What will be the output of the given program?
#include<stdio.h>
void main()
{
	float num=5.6;
	switch(num){
		case 5:printf("5");
		case 6:printf("6");
		default : printf("0");
			break;

	}
	printf("%d", num);
}
Discuss
Answer & Solution
Answer: Option D
Solution:

compiler error switch expression is not integral. switch statement cannot work on float value.