Fundamental Of C Programming

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Shivangi
S
Shivangi
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,178
| Attempts: 1,178 | Questions: 25
Please wait...
Question 1 / 25
0 %
0/100
Score 0/100
1. 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;} 

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.

Submit
Please wait...
About This Quiz
Fundamental Of C Programming - Quiz

This quiz titled 'Fundamental of C programming' assesses core aspects of C programming, including syntax, control structures, and error handling. It is designed to test understanding and application of basic C programming concepts, making it relevant for beginners and intermediate learners looking to solidify their programming skills.

Personalize your quiz and earn a certificate with your name on it!
2. 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);    } 

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.

Submit
3. 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;} 

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

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

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.

Submit
5. Which of the following is not a valid variable name declaration?

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.

Submit
6. Scanf () can be used for reading

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.

Submit
7. Which is valid C expression ?

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.

Submit
8. Continue statement is allowed inside the switch case statement ?

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.

Submit
9. 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;} 

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

Submit
10. We can not use string in the switch case as label ?

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.

Submit
11. 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++;            continue;        }    } 

Explanation

not-available-via-ai

Submit
12. The keyword 'break' cannot be simply used within:

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.

Submit
13. Which of the following can not be checked in a switch case statement ?

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.

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

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.

Submit
15. The control automatically passes to the first statement after the loop in

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.

Submit
16. 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);   } 

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

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

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

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

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.

Submit
19. 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;    } 

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.

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

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

Submit
21.  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);

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.

Submit
22. 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;        }    } 

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.

Submit
23. 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);    } 

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.

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

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.

Submit
25. 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;} 

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.

Submit
View My Results

Quiz Review Timeline (Updated): Feb 17, 2023 +

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
Cancel
  • All
    All (25)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What will be the valid value of x by which we can print...
What is the output of this C code?#include...
Guess the output of the following programme...
How many times below for loop will be executed...
Which of the following is not a valid variable name declaration?
Scanf () can be used for reading
Which is valid C expression ?
Continue statement is allowed inside the switch case statement ?
Find output of the following programme ?#include<stdio.h>int...
We can not use string in the switch case as label ?
What is the output of this C code?#include...
The keyword 'break' cannot be simply used within:
Which of the following can not be checked in a switch case statement ?
What is the output of this C code?    #include...
The control automatically passes to the first statement after the loop...
What is the output of this C code?#include...
What is the output of this C code?    #include...
What is the output of this C code?#include <stdio.h>void...
What is the output of this C code?    #include...
What is the output of this C code?#include...
 Number of times while loop condition is tested is, i is...
What is the output of this C code?#include...
What is the output of this C code?   #include...
Consider the following C code:{int a=5,b=9;float r;r=b/a;}What is the...
Guess the output of the following programme...
Alert!

Advertisement