Class 6 Exam  >  Class 6 Tests  >  C Programming for Beginners  >  Test: C Constants - Class 6 MCQ

Test: C Constants - Class 6 MCQ


Test Description

15 Questions MCQ Test C Programming for Beginners - Test: C Constants

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

What will be the output of the following C code?

    #include <stdio.h>
    int main()
    {
        enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
        printf("PEACH = %d\n", PEACH);
    }

Detailed Solution for Test: C Constants - Question 1

In enum, the value of constant is defined to the recent assignment from left.
Output:
$ cc pgm1.c
$ a.out
PEACH = 5

Test: C Constants - Question 2

In the following code snippet, character pointer str holds a reference to the string ___________

char *str =  "Sanfoundry.com\0" "training classes";

Detailed Solution for Test: C Constants - Question 2

‘\0’ is accepted as a char in the string. Even though strlen will give length of string “Sanfoundry.com”, in memory str is pointing to entire string including training classes.

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

What will be the output of the following C code?

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

Detailed Solution for Test: C Constants - Question 3

010 is octal representation of 8.
Output:
$ cc pgm4.c
$ a.out
8

Test: C Constants - Question 4

What will be the output of the following C code?

    #include <stdio.h>
    #define MAX 2
    enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};
    int main()
    {
        enum bird b = PARROT;
        printf("%d\n", b);
        return 0;
    }

Detailed Solution for Test: C Constants - Question 4

MAX value is 2 and hence PARROT will have value 3 + 2.
Output:
$ cc pgm6.c
$ a.out
5

Test: C Constants - Question 5

Enum types are processed by _________

Test: C Constants - Question 6

What will be the output of the following C code?

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

Detailed Solution for Test: C Constants - Question 6

rn combination makes the cursor move to the next line.
Output:
$ cc pgm9.c
$ a.out
sanfoundry
class

Test: C Constants - Question 7

What will be the output of the following C code?

    #include <stdio.h>
    void main()
    {
        int k = 4;
        int *const p = &k;
        int r = 3;
        p = &r;
        printf("%d", p);
    }

Detailed Solution for Test: C Constants - Question 7

Since the pointer p is declared to be constant, trying to assign it with a new value results in an error.
Output:
$ cc pgm11.c
pgm11.c: In function ‘main’:
pgm11.c:7: error: assignment of read-only variable ‘p’
pgm11.c:8: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int * const’

Test: C Constants - Question 8

What will be the output of the following C code?

    #include <stdio.h>
    void main()
    {
        int const k = 5;
        k++;
        printf("k is %d", k);
    }

Detailed Solution for Test: C Constants - Question 8

Constant variable has to be declared and defined at the same time. Trying to change it results in an error.
Output:
$ cc pgm12.c
pgm12.c: In function ‘main’:
pgm12.c:5: error: increment of read-only variable ‘k’

Test: C Constants - Question 9

What will be the output of the following C code?

    #include <stdio.h>
    int main()
    {
        printf("C programming %s", "Class by\n%s Sanfoundry", "WOW");
    }

Detailed Solution for Test: C Constants - Question 9

This program has only one %s within first double quotes, so it does not read the string “WOW”.
The %s along with the Sanfoundry is not read as a format modifier while new line character prints the new line.
Output:
$ cc pgm2.c
$ a.out
C programming Class by
%s Sanfoundry

Test: C Constants - Question 10

What will be the output of the following C code?

    #include <stdio.h>
    #define a 10
    int main()
    {
        const int a = 5;
        printf("a = %d\n", a);
    }

Detailed Solution for Test: C Constants - Question 10

The #define substitutes a with 10 without leaving any identifier, which results in Compilation error.
Output:
$ cc pgm3.c
pgm3.c: In function ‘main’:
pgm3.c:5: error: expected identifier or ‘(’ before numeric constant

Test: C Constants - Question 11

What will be the output of the following C function?

    #include <stdio.h>
    enum birds {SPARROW, PEACOCK, PARROT};
    enum animals {TIGER = 8, LION, RABBIT, ZEBRA};
    int main()
    {
        enum birds m = TIGER;
        int k;
        k = m;
        printf("%d\n", k);
        return 0;
    }

Detailed Solution for Test: C Constants - Question 11

m is an integer constant, hence it is compatible.
Output:
$ cc pgm5.c
$ a.out
8

Test: C Constants - Question 12

What will be the output of the following C code?

    #include <stdio.h>
    #include <string.h>
    int main()
    {
        char *str = "x";
        char c = 'x';
        char ary[1];
        ary[0] = c;
        printf("%d %d", strlen(str), strlen(ary));
        return 0;
    }

Detailed Solution for Test: C Constants - Question 12

str is null terminated, but ary is not null terminated.
Output:
$ cc pgm7.c
$ a.out
1 5

Test: C Constants - Question 13

What will be the output of the following C code?

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

Detailed Solution for Test: C Constants - Question 13

r is carriage return and moves the cursor back. sanfo is replaced by class.
Output:
$ cc pgm8.c
$ a.out
classundry

Test: C Constants - Question 14

What will be the output of the following C code?

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

Detailed Solution for Test: C Constants - Question 14

Since the constant variable has to be declared and defined at the same time, not doing it results in an error.
Output:
$ cc pgm10.c
pgm10.c: In function ‘main’:
pgm10.c:5: error: assignment of read-only variable ‘p’

Test: C Constants - Question 15

Which of the following statement is false?

Detailed Solution for Test: C Constants - Question 15

Since the constant variable has to be declared and defined at the same time, not doing it results in an error.

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

Top Courses for Class 6

10 videos|13 docs|15 tests
Download as PDF

Top Courses for Class 6