C Questions

0 votes, 0 avg
732

C Questions

1 / 15

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

        #include 

        #include 

        int main()

        {

            char line[3];

            FILE *fp;

            fp = fopen("newfile.txt", "r");

            while (fgets(line, 3, fp))

            fputs(line, stdout);

            return 0;

        }

2 / 15

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

        #include 

        int main()

        {

            int a = 1, b = 2, c = 3;

            int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;

            int **sptr = &ptr1; //-Ref

            *sptr = ptr2;

        }

3 / 15

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

#include 
void solve() {
    int a = 3;
    int res = a++ + ++a + a++ + ++a;
    printf("%d", res);
}
int main() {
solve();
return 0;
}

4 / 15

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

        #include 

        void foo(int *ary[]);

        int main()

        {

            int ary[2][3];

            foo(ary);

        }

        void foo(int *ary[])

        {

            int i = 10, j = 2, k;

            ary[0] = &i;

            ary[1] = &j;

            *ary[0] = 2;

            for (k = 0;k < 2; k++)

            printf("%dn", *ary[k]);

        }

5 / 15

5. Which of the following is the correct syntax to declare a 3 dimensional array using pointers?

6 / 15

6. What will happen if a header file is included in a program twice?

7 / 15

7. Which of the following is a correct format for declaration of function?

8 / 15

8. Which of the following is not a valid C variable name?

9 / 15

9. What is output of below code?


int main()
{
char name[]="Cppbuz";
int len;
int size;
len = strlen(name);
size = size_of(name);
printf("%d,%d",len,size);
return 0;
}

10 / 15

10. Multiple values of the same variable can be tested using ___.

11 / 15

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

#include 

int main(){
    int i, j;

    for (i = 2; i < 10; i++) {
        for (j = 2; j <= (i / j); j++)
            if (!(i % j))
                break;
        if (j > (i / j))
            printf("%d ", i);
    }

    return 0;
}

12 / 15

12. 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");

        }

13 / 15

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

14 / 15

14. Which of the following option is the correct representation of the following C statement?

e = a * b + c / d * f;

15 / 15

15. 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;    
    }     

Your score is

The average score is 38%

0%

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