# Fundamental Of C Programming

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
| By Shivangi
S
Shivangi
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,124
Questions: 25 | Attempts: 1,124

Settings

• 1.

### Which of the following is not a valid variable name declaration?

• A.

Int __a3;

• B.

Int 3_a;

• C.

Int __A3;

• D.

Int number;

B. Int 3_a;
Explanation
The variable name "3_a" is not a valid variable name declaration because it starts with a number. In most programming languages, variable names cannot start with a number, they must start with a letter or an underscore. Therefore, "int 3_a;" is not a valid declaration.

Rate this question:

• 2.

### Which is valid C expression ?

• A.

Int my_num = 100,000;

• B.

Int my num = 1000;

• C.

Int \$my_num = 10000;

• D.

Int my_num = 100000;

D. Int my_num = 100000;
Explanation
The valid C expression is "int my_num = 100000;". This is because it follows the correct syntax for declaring and initializing an integer variable in C. The variable name "my_num" is valid, and it is assigned the value of 100000. The other options either have invalid variable names or incorrect syntax, such as the use of a comma or a space in the variable name.

Rate this question:

• 3.

### What is the output of this C code?    #include <stdio.h>    int main()    {        int y = 10000;        int y = 34;        printf("Hello World! %d\n", y);        return 0;    }

• A.

Hello World! 1000

• B.

Hello World! 34

• C.

Compile time error

• D.

Hello World! followed by a junk value

C. Compile time error
Explanation
The code will result in a compile-time error because it is trying to declare the variable "y" twice. In C, each variable must have a unique name within its scope. Since the code is trying to declare "y" twice, the compiler will throw an error.

Rate this question:

• 4.

### How many times below for loop will be executed ?#include<stdio.h>int main(){    int i=0;    for(;;)        printf("%d",i);    return 0;}

• A.

10 times

• B.

Infinite times

• C.

1 time

• D.

0 time

B. Infinite times
Explanation
The for loop in the given code does not have any condition specified in the middle section. This means that the loop will continue to execute indefinitely until it is explicitly terminated using a break statement or some other means. Therefore, the loop will be executed infinite times.

Rate this question:

• 5.

### Find output of the following programme ?#include<stdio.h>int main(){    char str[] = "Smaller";    int a = 100;    printf(a > 10 ? "Greater" : "%s", str);    return 0;}

• A.

Compile error

• B.

Greater

• C.

100

• D.

Smaller

B. Greater
Explanation
The output of the program will be "Greater". This is because the program uses a ternary operator to check if the value of 'a' is greater than 10. Since 'a' is equal to 100, which is greater than 10, the condition is true and the program will print "Greater".

Rate this question:

• 6.

### Guess the output of the following programme ?#include<stdio.h>int main(){    int a = 100, b = 200, c = 300;    if(!a >= 500)        b = 300;    c = 400;    printf("%d,%d,%d",a, b, c);    return 0;}

• A.

100,200,300

• B.

100,300,400

• C.

100,200,400

• D.

100,300,300

C. 100,200,400
Explanation
The program initializes three variables, a, b, and c, with values 100, 200, and 300 respectively. The if statement checks if the logical NOT of a greater than or equal to 500 is true. Since a is 100, which is not greater than or equal to 500, the condition evaluates to true. Therefore, the statement b = 300; is not executed. The statement c = 400; is executed regardless of the if condition. Finally, the printf statement prints the values of a, b, and c which are 100, 200, and 400 respectively. Hence, the output of the program is 100, 200, 400.

Rate this question:

• 7.

### Guess the output of the following programme ?#include<stdio.h>int main(){    int x = 10;    float y = 10.0;    if(x == y)        printf("x and y are equal");    else        printf("x and y are not equal");    return 0;}

• A.

X and y are not equal

• B.

X and y are equal

• C.

Run time error

• D.

Compile error

B. X and y are equal
Explanation
The program compares the integer variable x with the float variable y using the equality operator. Since the values of x and y are both 10, the condition x == y is true. Therefore, the program will output "x and y are equal".

Rate this question:

• 8.

### We can not use string in the switch case as label ?

• A.

True

• B.

False

A. True
Explanation
In a switch case statement, the labels used must be constant expressions that can be evaluated at compile time. Since strings are not considered constant expressions in most programming languages, they cannot be used as labels in a switch case. Instead, switch cases typically use integer or character constants as labels. Therefore, the statement "We can not use string in the switch case as label" is true.

Rate this question:

• 9.

### Which of the following can not be checked in a switch case statement ?

• A.

Integer

• B.

Float

• C.

Char

• D.

Enum

B. Float
Explanation
A switch case statement can be used to check for integer values, character values, and enumerated values. However, it cannot be used to check for float values. This is because switch case statements can only evaluate discrete values, and floating-point numbers are continuous values. Therefore, float cannot be checked in a switch case statement.

Rate this question:

• 10.

### Continue statement is allowed inside the switch case statement ?

• A.

Yes

• B.

No

B. No
Explanation
The answer is "No" because the switch case statement does not allow the use of the continue statement. The continue statement is used to skip the rest of the code in a loop and move to the next iteration, but it cannot be used inside a switch case statement. Instead, the break statement is used to exit the switch case block.

Rate this question:

• 11.

### What will be the valid value of x by which we can print "DEF" ?#include<stdio.h>int main(){int x = _________ ;   if(x)        printf("ABC");  else        printf("DEF"); return 0;}

• A.

0

• B.

'A'

• C.

'0'

• D.

-9

A. 0
Explanation
In the given code, the condition in the if statement is checking the value of x. If the value of x is non-zero, the condition will be true and "ABC" will be printed. However, if the value of x is zero, the condition will be false and "DEF" will be printed. Therefore, in order to print "DEF", the valid value of x should be 0.

Rate this question:

• 12.

### What is the output of this C code?    #include <stdio.h>    int main()    {        int x = 0;        if (x++)            printf("true\n");        else if (x == 1)            printf("false\n");    }

• A.

True

• B.

False

• C.

Compile time error

• D.

Undefined behaviour

B. False
Explanation
The output of this C code will be "false". The code initializes the variable x to 0. In the if statement, x is incremented using the post-increment operator, but the value of x is still 0 at the time of evaluation. Since the condition in the if statement is false, the code moves to the else if statement. Here, x is compared to 1, and since x is still 0, the condition is also false. Therefore, the code reaches the end without printing anything.

Rate this question:

• 13.

### What is the output of this C code?    #include <stdio.h>    int main()    {        int x = 0;        if (x == 1)            if (x == 0)                printf("inside if\n");            else                printf("inside else if\n");        else            printf("inside else\n");    }

• A.

Inside if

• B.

Inside else if

• C.

Inside else

• D.

Compile time error

C. Inside else
Explanation
The code snippet checks the value of the variable x. Since x is initially assigned a value of 0, the condition "if (x == 1)" evaluates to false. Therefore, the code moves to the "else" block and prints "inside else".

Rate this question:

• 14.

### The control automatically passes to the first statement after the loop in

• A.

Break statement

• B.

Continue statement

• C.

If statement

• D.

Switch statement

B. Continue statement
Explanation
The continue statement is used in loops to skip the rest of the current iteration and move on to the next iteration. Therefore, when the continue statement is encountered, the control automatically passes to the first statement after the loop. This allows the program to skip any remaining code within the loop and proceed with the next iteration.

Rate this question:

• 15.

### Consider the following C code:{int a=5,b=9;float r;r=b/a;}What is the value of r?

• A.

1.8

• B.

1.0

• C.

2.0

• D.

0.0

B. 1.0
Explanation
The value of r is 1.0 because in the given code, the variables a and b are both integers, so when dividing b by a, the result will also be an integer. In this case, 9 divided by 5 equals 1.8, but since r is declared as a float, the decimal part is truncated and the value of r becomes 1.0.

Rate this question:

• 16.

### What is the output of this C code?   #include <stdio.h>    void main()    {        double k = 0;        for (k = 0.0; k < 3.0; k++);            printf("%lf", k);    }

• A.

2.000000

• B.

4.000000

• C.

3.000000

• D.

Run time error

C. 3.000000
Explanation
The code initializes a variable 'k' to 0 and then enters a for loop. The loop condition checks if 'k' is less than 3, and if true, increments 'k' by 1. However, the loop body is empty, indicated by the semicolon immediately after the loop declaration. Therefore, the loop runs until 'k' becomes 3, and then the loop terminates. After the loop, the value of 'k' is printed, which is 3.000000.

Rate this question:

• 17.

### What is the output of this C code?#include <stdio.h>    void main()    {        int k;        for (k = -3; k < -5; k++)            printf("Hello");    }

• A.

Hello

• B.

Infinite hello

• C.

Run time error

• D.

Nothing

D. Nothing
Explanation
The output of this C code is "Nothing" because the condition of the for loop is already false. The initial value of k is -3 and the condition is k < -5. Since -3 is not less than -5, the for loop does not execute and the printf statement is not executed. Therefore, there is no output and the program terminates without printing anything.

Rate this question:

• 18.

### What is the output of this C code?#include <stdio.h>void main(){    int i = 0;    while (i < 10)    {        i++;        printf("hi\n");        while (i < 8) {            i++;            printf("hello\n");        }    }}

• A.

Hi is printed 8 times, hello 7 times and then hi 2 times

• B.

Hi is printed 10 times, hello 7 times

• C.

Hi is printed once, hello 7 times

• D.

Hi is printed once, hello 7 times and then hi 2 times

D. Hi is printed once, hello 7 times and then hi 2 times
Explanation
The code starts with initializing the variable i to 0. Then, it enters a while loop that will execute as long as i is less than 10. Inside the loop, i is incremented by 1 and "hi" is printed. Then, it enters another while loop that will execute as long as i is less than 8. Inside this loop, i is incremented by 1 and "hello" is printed. After this inner loop finishes, the control goes back to the outer loop and "hi" is printed again. This process continues until i becomes 10. Therefore, the output will be "Hi" printed once, "hello" printed 7 times, and "hi" printed 2 times.

Rate this question:

• 19.

### Number of times while loop condition is tested is, i is initialized to 0 in both case.     while (i < n)         i++;    -------------    do         i++;    while (i <= n);

• A.

N, n

• B.

N+1, n+1

• C.

N, n+1

• D.

N+1, n

B. N+1, n+1
Explanation
In the first case, the while loop condition is tested n times because i is incremented by 1 each time until it becomes equal to n. In the second case, the do-while loop condition is tested n+1 times because i is incremented by 1 before the condition is checked, and it becomes equal to n+1 when the loop ends. Therefore, the correct answer is n+1, n+1.

Rate this question:

• 20.

• A.

2

• B.

3

• C.

4

• D.

5

D. 5
• 21.

### What is the output of this C code?#include <stdio.h>    int main()    {        int a = 0, i = 0, b;        for (i = 0;i < 5; i++)        {            a++;            if (i == 3)                break;        }    }

• A.

2

• B.

4

• C.

1

• D.

3

B. 4
Explanation
The output of this C code is 4.
In the for loop, the variable i is initialized to 0 and the loop continues as long as i is less than 5.
Inside the loop, the variable a is incremented by 1 each time.
When i reaches 3, the condition i == 3 is true and the loop is terminated using the break statement.
Therefore, the loop runs 4 times (i=0, i=1, i=2, i=3) and the final value of a is 4.

Rate this question:

• 22.

### The keyword ‘break’ cannot be simply used within:

• A.

Do-while

• B.

If-else

• C.

For

• D.

While

B. If-else
Explanation
In the if-else statement, the keyword "break" cannot be used because "break" is used to exit a loop or switch statement. In an if-else statement, there is no looping construct, so there is no need to exit from it. Instead, the if-else statement is used to make a decision and execute different blocks of code based on a condition. Therefore, using "break" in an if-else statement would be unnecessary and invalid.

Rate this question:

• 23.

### What is the output of this C code?#include <stdio.h>    int main()    {        printf("%d ", 1);        goto l1;        printf("%d ", 2);        l1:goto l2;        printf("%d ", 3);        l2:printf("%d ", 4);   }

• A.

1 4

• B.

Compile time error

• C.

1 2 4

• D.

1 3 4

A. 1 4
Explanation
The output of this C code is "1 4".

The code starts by printing "1" using the printf() function. Then, it encounters a "goto" statement which transfers the control to the label "l1". The code then prints "3" using another printf() function. After that, it encounters another "goto" statement which transfers the control to the label "l2". Finally, it prints "4" using the printf() function. So, the output is "1 4".

Rate this question:

• 24.

### What is the output of this C code?#include <stdio.h>    void main()    {        int a = 2 + 3 - 4 + 8 -  5 % 4;        printf("%d\n", a);    }

• A.

0

• B.

8

• C.

11

• D.

9

B. 8
Explanation
The code calculates the value of the expression "2 + 3 - 4 + 8 - 5 % 4". The modulus operator "%" calculates the remainder of the division operation. In this case, 5 % 4 equals 1. The expression simplifies to "2 + 3 - 4 + 8 - 1", which further simplifies to "8". Therefore, the output of the code is 8.

Rate this question:

• 25.

### Scanf () can be used for reading

• A.

Double character

• B.

Single character

• C.

Multiple character

• D.

No character

C. Multiple character
Explanation
The scanf() function in C can be used for reading multiple characters. It allows the user to input a sequence of characters until a specified delimiter is encountered. This can be useful when reading strings or multiple values from the user. The function scans the input and stores it in the specified variables or buffers. By using appropriate format specifiers, such as %s for strings, scanf() can efficiently read multiple characters from the user.

Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

• Current Version
• Feb 17, 2023
Quiz Edited by
ProProfs Editorial Team
• Aug 23, 2015
Quiz Created by
Shivangi

Related Topics