C Programming Quiz – Set 1

Programming Questions & Answers -
You should practice these quizzes to improve your C programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams.

#1: Which is valid C expression?
a) int my_num = 100,000;
b) int my_num = 100000;
c) int my num = 1000;
d) int $my_num = 10000;

Show Answer

#2: What is the output of this C code?

#include <stdio.h>
int main()
{
	printf("Hello World! %d \n", x);
	return 0;
}

a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!

Show Answer

#3: What will happen if the below program is executed?

    #include <stdio.h>
    int main()
    {
        int main = 3;
        printf("%d", main);
        return 0;
    }

a) It will cause a compile-time error
b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping

Show Answer

#4: What is the output of this C code?

    #include  <stdio.h>
    int main()
    {
       char chr;
       chr = 128;
       printf("%d\n", chr);
       return 0;
    }

a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned

Show Answer

#5: What is the output of this C code?

    #include <stdio.h>
    int main()
    {
        char *p[1] = {"hello"};
        printf("%s", (p)[0]);
        return 0;
    }

a) Compile time error
b) Undefined behaviour
c) hello
d) None of the mentioned

Show Answer

#6: What is the output of this C code?

    #include <stdio.h>
    int main()
    {
        printf("crazyfor\code\n");
        return 0;
    }

a) crazyforcode
b) crazyfor
code
c) codeyfor
d) crazyfor

Show Answer

#7: Which among the following is NOT a logical or relational operator?
a) !=
b) ==
c) ||
d) =

Show Answer

#8: What is the output of this C code?

    #include <stdio.h>
    int main()
    {
        int a = 10;
        if (a == a--)
            printf("TRUE 1\t");
        a = 10;
        if (a == --a)
            printf("TRUE 2\t");
    }

a) TRUE 1
b) TRUE 2
c) TRUE 1 TRUE 2
d) No output

Show Answer

#9: The scope of an automatic variable is:
a) Within the block it appears
b) Within the blocks of the block it appears
c) Until the end of program
d) Both (a) and (b)

Show Answer

#10: Default storage class if not any is specified for a local variable, is auto
a) true
b) false
c) Depends on the standard
d) None of the mentioned

Show Answer

24 Thoughts on “C Programming Quiz – Set 1

  1. Aiswarya on October 7, 2014 at 6:04 pm said:

    Can anybody please explain me why is the answer for q#8
    #include
    int main()
    {
    int a = 10;
    if (a == a–)
    printf(“TRUE 1\t”);
    a = 10;
    if (a == –a)
    printf(“TRUE 2\t”);
    }
    is TRUE1 TRUE2

  2. Vignesh M on June 21, 2015 at 9:33 am said:

    Operator precedence

  3. pagsiu on June 15, 2016 at 3:50 pm said:

    #6 is wrong, there is no \c escape sequence…

  4. atanu on July 29, 2016 at 1:32 am said:

    To,
    surendra maharajan
    1st let me tell u that — before variable is knowm as prefix operator and other one is postfix operator,
    in prefix operator first the value of the variable is changed and then its assigned to the left variable,
    in case of if(a==a–),
    so the value of a is defined to be 10,and when a– is executed it first decreases the value of a by 1 below(==) operator and now the value of a is 9 and now the work of (a–) comes thats it has to decrease by 1,since the value of a is now 9 the value will become 8 for (a–),
    now what happens in
    if(a=–a)
    value of a=10;
    first it will become 9 due to(–a) and then it will assign to 9 to the left variable,so the value of a is 9 on both side,

    thank u

  5. balaji ramani on August 5, 2016 at 2:48 pm said:

    for #8 given answer is correct, a becomes 9 when –a and comparison results if(9==9) ok, what happens if (–a==a) in this case also TRUE2 is coming

  6. Mohammad yasin on September 29, 2016 at 1:08 pm said:

    answer is option c.true 1 true 2!
    ! because( – - ) decrement operator has more preority than (==) equal too !! so in both if condition before comparing the decrement is done hence option C is the correct amswer

  7. int main()
    {
    int x = 1;
    short int i = 2;
    float f = 3.5;
    if(sizeof((x == 2) ? f : i) == sizeof(float))
    printf(“float”);
    else
    printf(“int”);
    }

  8. BRAJ Kishore Bharti on February 28, 2018 at 4:30 pm said:

    #4
    Depends on the compiler when you run this code on GCC compiler you will get 128 as output.

  9. BRAJ Kishore Bharti on February 28, 2018 at 4:31 pm said:

    #3
    It will run without error and prints 3

  10. BRAJ Kishore Bharti on February 28, 2018 at 5:54 pm said:

    #8
    Answer is True 2.

  11. BRAJ Kishore Bharti on February 28, 2018 at 5:56 pm said:

    #9
    Answer is a

  12. tttt on May 22, 2018 at 11:35 am said:

    question no 6 i don’t think so which you mentioned is correct answer, because i got output as carzyforcode

  13. samantha on September 18, 2018 at 10:35 am said:

    it think 6th one answer is crazyforcode. if the printf statement is printf(“crazyfo\rcode\n”); then the output will be codeyfo.

  14. Hanamant Bhoomar on February 28, 2019 at 8:48 am said:

    True 1 correct because a– is become 10 it is post decremeny

Leave a Reply to Mohammad yasin Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation