Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Tests  >  Test: Control structures in C - Computer Science Engineering (CSE) MCQ

Test: Control structures in C - Computer Science Engineering (CSE) MCQ


Test Description

10 Questions MCQ Test - Test: Control structures in C

Test: Control structures in C for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Test: Control structures in C questions and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus.The Test: Control structures in C MCQs are made for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Control structures in C below.
Solutions of Test: Control structures in C questions in English are available as part of our course for Computer Science Engineering (CSE) & Test: Control structures in C solutions in Hindi for Computer Science Engineering (CSE) course. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free. Attempt Test: Control structures in C | 10 questions in 30 minutes | Mock test for Computer Science Engineering (CSE) preparation | Free important questions MCQ to study for Computer Science Engineering (CSE) Exam | Download free PDF with solutions
Test: Control structures in C - Question 1

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

Detailed Solution for Test: Control structures in C - Question 1

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.

Test: Control structures in C - Question 2

What is the output of given program if user enter "xyz" ?

#include
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);
}

Detailed Solution for Test: Control structures in C - Question 2

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.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Control structures in C - Question 3

What will be the output of the given program?

#include<stdio.h>
void main()
{
      int value=0;
      if(value)
            printf("well done ");
      printf("Edurev");
}

Detailed Solution for Test: Control structures in C - Question 3

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

Test: Control structures in C - Question 4

What is the output of given program if user enter "xyz" ?

#include
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);

}

Detailed Solution for Test: Control structures in C - Question 4

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.

Test: Control structures in C - Question 5

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

Detailed Solution for Test: Control structures in C - Question 5
  1. Initial values:

    • a = 11
    • b = 5
  2. Condition in if statement:

    • if(a=5) is an assignment, not a comparison. This assigns 5 to a, so a becomes 5. The condition if(a=5) evaluates to true (non-zero), so the code inside the if block executes, incrementing b by 1.
    • After if block: b = 6.
  3. After if block:

    • a = 5
    • b = 6
  4. printf statement:

    • ++a increments a before its value is used, so ++a becomes 6.
    • b++ uses the current value of b (which is 6), then increments b after its value is used.
    • Therefore, b++ results in 6, and b becomes 7 after the statement.
  5. Output:

    • ++a results in 6
    • b++ results in 6

So, the output of the program is:

3. 6 6

Test: Control structures in C - Question 6

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

Detailed Solution for Test: Control structures in C - Question 6
  1. Initial declaration:

    • int i = 10; declares and initializes i to 10.
    • The first printf statement prints i as 10.
  2. Inner block:

    • A new variable i is declared inside the block and initialized to 20. This i shadows the outer i.
    • The second printf statement prints the inner i as 20.
    • The statement i++; increments the inner i to 21.
    • The third printf statement prints the incremented inner i as 21.
  3. After the inner block:

    • The control exits the inner block, and the inner i goes out of scope. The outer i is still 10.
    • The last printf statement prints the outer i as 10.

So, the output of the program is:

3. 10 20 21 10

Test: Control structures in C - Question 7

What will be the output given program?

#include<stdio.h>
void main()
{
    int i = -10;
    for(;i;printf("%d ", i++));
}

Detailed Solution for Test: Control structures in C - Question 7

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.

Test: Control structures in C - Question 8

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

Detailed Solution for Test: Control structures in C - Question 8

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.

Test: Control structures in C - Question 9

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

Detailed Solution for Test: Control structures in C - Question 9

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.

Test: Control structures in C - Question 10

What will be the output of the given program?

#include
void main()
{
    float num=5.6;
    switch(num){
        case 5:printf("5");
        case 6:printf("6");
        default : printf("0");
            break;

    }
    printf("%d", num);
}

Detailed Solution for Test: Control structures in C - Question 10

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

Information about Test: Control structures in C Page
In this test you can find the Exam questions for Test: Control structures in C solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Control structures in C, EduRev gives you an ample number of Online tests for practice

Top Courses for Computer Science Engineering (CSE)

Download as PDF

Top Courses for Computer Science Engineering (CSE)