C Questions

0 votes, 0 avg
749

C Questions

1 / 15

1. What will be the output of the following C code?

        #include 

        int *m();

        void main()

        {

            int *k = m();

            printf("hello ");

            printf("%d", k[0]);

        }

        int *m()

        {

            int a[2] = {5, 8};

            return a;

        }

2 / 15

2. What will be the output of the following code snippet?

#include 
void solve() {
    int first = 10, second = 20;
    int third = first + second;
    {
        int third = second - first;
        printf("%d ", third);
    }
    printf("%d", third);
}
int main() {
solve();
return 0;
}

3 / 15

3. What will be the output of this program?

    int main()      
    {      
    int a=10, b=20;        
    printf("a=%d b=%d",a,b);        
    a=a+b;      
    b=a-b;      
    a=a-b;      
    printf("a=%d b=%d",a,b);      
    return 0;    
    }     

4 / 15

4. What will be the output of the following C code?

        #include 

        void main()

        {

            double k = 0;

            for (k = 0.0; k < 3.0; k++)

                printf("Hello");

        }

5 / 15

5. What will be the output of the following C code?

#include 

int main()
{
    float x = 23.456;
    printf("%.2f",x);
    return 0;
}

6 / 15

6. What will be the output of the following C program?

#include 

union values {
    int val1;
    char val2;
} myVal;

int main()
{
    myVal.val1 = 66;
    
    printf("val1 = %p", &myVal.val1);
    printf("nval2 = %p", &myVal.val2);
    
    return 0;
}

7 / 15

7. What is an example of iteration in C?

8 / 15

8. What is the output of the following code snippet?

#include 
int main() {
	int a[] = {1, 2, 3, 4};
	int sum = 0;
	for(int i = 0; i < 4; i++) {
	    sum += a[i];
	}
	printf("%d", sum);
	return 0;
}

9 / 15

9. What does argc and argv indicate in command-line arguments?
(Assuming: int main(int argc, char *argv[]) )

10 / 15

10. The standard header _______ is used for variable list arguments (…) in C.

11 / 15

11. What will be the output of the following C code considering the size of a short int is 2, char is 1 and int is 4 bytes?

        #include 

        int main()

        {

            short int i = 20;

            char c = 97;

            printf("%d, %d, %dn", sizeof(i), sizeof(c), sizeof(c + i));

            return 0;

        }

12 / 15

12. What will be the output of the following C code?

        #include 

        struct student

        {

            char *name;

        };

        struct student s[2];

        void main()

        {

            s[0].name = "alan";

            s[1] = s[0];

            printf("%s%s", s[0].name, s[1].name);

            s[1].name = "turing";

            printf("%s%s", s[0].name, s[1].name);

        }

13 / 15

13. What is the use of symbol * in the control string as shown [=%[*][width] [modifiers] type=]?

14 / 15

14. What will be the output of the following code snippet?

#include 
void solve() {
    int a[] = {1, 2, 3, 4, 5};
    int sum = 0;
    for(int i = 0; i < 5; i++) {
        if(i % 2 == 0) {
            sum += *(a + i);
        }
        else {
            sum -= *(a + i);
        }
    }
    printf("%d", sum);
}
int main() {
solve();
return 0;
}

15 / 15

15. Which statement is required to execute a block of code when the condition is false?

Your score is

The average score is 38%

0%

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top