ADMICRO

400 Câu hỏi trắc nghiệm lập trình C/C++ có đáp án và lời giải chi tiết

Tổng hợp câu hỏi trắc nghiệm lập trình C/C++ có đáp án và lời giải đầy đủ nhằm giúp các bạn dễ dàng ôn tập lại toàn bộ các kiến thức. Để ôn tập hiệu quả các bạn có thể ôn theo từng phần trong bộ câu hỏi này bằng cách trả lời các câu hỏi và xem lại đáp án và lời giải chi tiết. Sau đó các bạn hãy chọn tạo ra đề ngẫu nhiên để kiểm tra lại kiến thức đã ôn.

400 câu
752 lượt thi

Chọn hình thức trắc nghiệm (50 câu/60 phút)

Chọn phần

  • Câu 1:

    What is output?

    void main()
    {
        int i = 5, k;
        if (i == 0)
            goto label;
    label: printf("%d", i);
        printf("Hey");
        getch();
    }

     


    A. Hey


    B. 5


    C. 5Hey


    D. Complie error


  • ADSENSE / 1
  • Câu 2:

     What is output?

    void main()
    {
        printf("%d ", 1);
        goto l1;
        printf("%d ", 2);
    l1:goto l2;
        printf("%d ", 3);
    l2:printf("%d ", 4);
        getch();
    }

     


    A. 1 4


    B. 1 2 3 4


    C.  Syntax error


    D. Syntax error


  • Câu 3:

    What is output?

    #include <conio.h>
    #include <stdio.h>
    void foo();
    int main()
    {
        printf("%d ", 1);
        goto l1;
        printf("%d ", 2);
    }
    void foo()
    { 
    l1: printf("3 ");
    }

     


    A. Complie error


    B. 3


    C. 1


    D. 1 3


  • Câu 4:

    What is output?

    #include <conio.h>
    #include <stdio.h>
    int main()
    {
        int i = 0, j = 0;
        while (i < 2)
        {
    l1: i++;
            while (j < 3)
            {
                printf("loop\n");
                goto l1;
            }
        }
        getch();
    }

     


    A. loop loop loop


    B. Infinite loop


    C. Complie error


  • ZUNIA12
  • Câu 5:

    What is output?

    void main()
    {
        int a = 15, b = 10, c = 5;
        if(a > b > c)
            printf("True");
        else
            printf("False"); 
        getch();
    }

     


    A. True


    B. False


    C. Complier Error


    D. Run time error


  • Câu 6:

     What is output?

    #include <stdio.h>
    #include <conio.h>
    void main()
    {
        int i = 0;
        switch (i)
        {
        case '0': printf("A");
            break;
        case '1': printf("B");
            break;
        default: printf("ABC");
        }
        getch();
    }

     


    A. A


    B. B


    C. ABC


  • ADMICRO
  • Câu 7:

    What is output?

    #include <stdio.h>
    #include "conio.h"
    void main()
    {
        int i = 3;
        switch (i)
        {
        case 0+1: printf("A");
            break;
        case 1+2: printf("B");
            break;
        default: printf("ABC");
        }
        getch();
    }

     


    A. A


    B. B


    C. ABC


  • Câu 8:

    What is output?

    #include <stdio.h>
    #include <conio.h>
    #define A 0
    #define B 1
    int main()
    {
        int i = 3;
        switch (i & 1)
        {
        case A: printf("FALSE");
            break;
        case B: printf("TRUE");
            break;
        default: printf("Default");
        }
        getch();
    }

     


    A. FALSE


    B. TRUE


    C.  Default


  • Câu 9:

    What is output?

    #include <stdio.h>
    #include <conio.h>
    int main()
    {
        int i;
        if (printf("0"))
            i = 3;
        else
            i = 5;
        printf("%d", i);
        getch();
    }

     


    A. 3


    B. 5


    C. 03


    D. 05


  • Câu 10:

    What is output?

    #include<stdio.h>
    #include <conio.h>
    int main()
    {
        int a = 5;
        switch(a)
        {
        default:
            a = 4;
        case 6:
            a--;
        case 5:
            a = a + 1;
        case 1:
            a = a - 1;
        }
        printf("%d \n", a);
        getch();
    }

     


    A. 3


    B. 4


    C. 5


    D. 6


  • Câu 11:

     What is output?

    #include <stdio.h>
    #include <conio.h>
    int main()
    {
        int x = 3;
        if (x == 2); x = 0;
        if (x == 3) x++;
        else x += 2;
     
        printf("x = %d", x);
        getch();
    }

     


    A. x = 2


    B.  x = 6


    C. x = 0


  • Câu 12:

    What is output?

    #include <stdio.h>
    #include <conio.h>
    int main()
    {
        int check = 20, arr[] = {10, 20, 30};
        switch (check)
        {
        case arr[0]: printf("A ");
        case arr[1]: printf("B");
        case arr[2]: printf("C");
        }
        getch();
    }

     


    A. ABC


    B. BC


    C. B


    D. Complier Error


  • Câu 13:

    What is output of code?

    void main() 
    {
        if ((1 || 0) && (0 || 1)) 
        {
            printf("ABC");
        } 
        else
        {
            printf("DEF");
        }
        getch();
    }

     


    A. ABC


    B. DEF


    C. Syntax error


  • Câu 14:

    What is output of code?

    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
     
    void main()
    {
        char str1[] = "vncoding";
        char str2[] = "vncoding";
        if (strcmp(str1, str2))
            printf("Equal");
        else
            printf("Unequal");
     
        getch();
    }

     


    A. Equal


    B. Unequal


    C. nothing is printed


  • Câu 15:

     What is output of code?

    #include <stdio.h>
    #include <conio.h>
     
    void main()
    {
        int i;
        i = 10;
        if(i == 20 || 30)
            printf("True");
        else
            printf("False");
     
        getch();
    }

     


    A. True


    B. False


    C. Complier error


  • Câu 16:

    What is output of code?

    #include <stdio.h>
    #include <conio.h>
     
    void main()
    {
        if(1,0)
            printf("True");
        else
            printf("False");
     
        getch();
    }

     


    A. True 


    B. False


    C. Complier error


  • Câu 17:

    What is output of code?

    #include <stdio.h>
    #include <conio.h>
     
    void main()
    {
        int i, j, *ptr, *ptr1;
        i = 10;
        j = 10;
        ptr = &i;
        ptr1 = &j;
     
        if(ptr == ptr1)
            printf("True");
        else
            printf("False");
     
        getch();
    }

     


    A. True


    B. False


    C. Complier error


  • Câu 18:

    What is output of code?

    #include <stdio.h>
    #include <conio.h>
     
    void main()
    {
        int i;
        i = 2;
    DES:
        printf("%d", i);
        i = i + 2;
        if(i <= 20)
            goto DES;
     

     


    A. 2468101214161820


    B. 468101214161820


    C. nothing is printed


  • Câu 19:

    What is output of code?

    #include <stdio.h>
    #include <conio.h>
     
    void main()
    {
        int i;
        i = 0;
        if(i = 15, 10, 5)
            printf("C/C++ %d", i);
        else
            printf("Java %d", i);
     
        getch();
    }

     


    A. C/C++ 15


    B. Java 15


    C. Java 5


    D. Complier error


  • Câu 20:

     What is output of code?

    #include <stdio.h>
    #include <conio.h>
     
    void main()
    {
        int a = 80;
        if(a++ > 80)
            printf("C/C++ %d", a);
        else
            printf("Java %d", a);
     
        getch();
    }

     


    A. C/C++ 80


    B.  C/C++ 81


    C.  Java 80


    D. Java 81


  • Câu 21:

    What is output of code?

    #include <stdio.h>
    #include <conio.h>
     
    void main()
    {
        int a;
        a = 1;
        while(a <= 1)
            if(a%2)
                printf("%d ", a++);
            else
                printf("%d ", ++a);
        printf("%d ", a+10);
     
        getch();
    }

     


    A. 1 12


    B. 2 12


    C. 2 11


  • Câu 22:

    What is output ?

    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <stdlib.h>
     
    void myfunc(char** param)
    {
        ++param;
    }
    void main()
    {
        char* string = (char*)malloc(64);
        strcpy(string, "hello_World");
        myfunc(&string);
        myfunc(&string);
        printf("%s\n", string);
        getch();
    }

     


    A. hello_World


    B. ello_World


    C. llo_World


    D. lo_World


  • Câu 23:

    What is output?

    void myfunc(char** param)
    {
        ++*param;
    }
    void main()
    {
        char* string = (char*)malloc(64);
        strcpy(string, "hello_World");
        myfunc(&string);
        myfunc(&string);
        printf("%s\n", string);
        getch();
    }

     


    A. hello_World


    B. ello_World


    C. llo_World


    D. lo_World


  • Câu 24:

    What is output?

    void main()
    {
        int ints[] = { 0, 1, 2, 3 };
        int* i1 = ints + 1;
        int a = ++*i1;
        int b = a + *i1;
        printf("%d\n", b);
        getch();
    }

     


    A. 3


    B. 4


    C. 5


    D. 6


  • Câu 25:

    What is output?

    void main()
    {
        int ints[] = { 0, 5, 10, 15 };
        int* i2 = ints + 2;
        int a = *i2++; // a = *(i2++);
        printf("%d#%d\n", a, *i2);
        getch();
    }

     


    A. 10#15


    B. 10#10


    C. 15#15


    D. 11#15


  • Câu 26:

    What is output of following code?

    void main()
    {
        int ints[] = { 0, 1, 2, 3 };
        int* i1 = ints + 1;
        int* i2 = ints + 2;
        int a = ++*i1 + *i2++;
        int b = *++i1 + *i2--;
        printf("%d#%d", a, b);
        getch();
    }

     


    A. 4#4


    B. 4#5


    C. 5#6


    D. 4#6


  • Câu 27:

     What is output of following code?

    void main()
    {
        int i = 400;
        int *ptr = &i;
        *++ptr = 2;
        printf("%d %d", i, *ptr);
        getch();
    }

     


    A. 400 2


    B. 400 400


    C. 400 401


    D. Complier error


  • Câu 28:

    What is output?

    void main()
    {
        char str[] = {"pvpit"};
        char *s1 = str;
        s1++;
        printf("%c", *s1);
        getch();
    }

     


    A. pvpit


    B. vpit


    C. v


    D. Another


  • Câu 29:

    What is output?

    void main()
    {
        char *s = "\12345s\n";
        printf("%d", strlen(s));
        printf("\n%s", s);
        getch();
    }

     


    A. 5


    B. 7


    C. 9


    D. 10


  • Câu 30:

     For the code below which lines should be reported as errors by a compiler?

    int main(int argc, char** argv)
    {
        const char* foo = "wow"; // line 1
        foo = "top"; // line 2
        foo[0] = 1; // line 3
        return 0;
    }

     


    A. 1


    B. 2


    C. 3


    D. None of the lines


  • Câu 31:

    What is output?

    void main() 
    { 
        int x = 5,y = 6;
        int* const p = &x;
        p = &y; 
        printf("%d", (*p)); 
        getch();
    }

     


    A. Complier error


    B. 6


    C. 5


    D. Another


  • Câu 32:

    What is output?

    void main() 
    { 
        int x = 5, y = 8;
        const int* p;
        p = &x;
        p = &y;
        x++;
        printf("%d", *p); 
        getch();
    }

     


    A. 5


    B. 6


    C. 8


    D. Complier Error


  • Câu 33:

     What is output of code?

    void main() 
    { 
        int x = 5;
        const int* p;
        p = &x;
        x++;
        *p = 4;
        printf("%d", *p); 
        getch();
    }

     


    A. 4


    B. 5


    C. 6


    D. Complier Error


  • Câu 34:

    What is output of code?

    #include <stdio.h>
     
    int main()
    {
        int a = 320;
        char *ptr;
        ptr = (char*)&a;
        printf("%d ", *ptr);
        return 0;
    }

     


    A. 320


    B. 64


    C. Complier Error


  • Câu 35:

    What will be output of following program?

    #include <stdio.h>
     
    int main()
    {
        int i = 3;
        int *j;
        int **k;
        j = &i;
        k = &j;
        printf("%u , %u , %d ", k, *k, **k);
        return 0;
    }

     


    A. Address of j , Address of  i , 3


    B. Complier Error


    C. 3 , 3 , 3


  • Câu 36:

    What will be output of following program?

    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
     
    int main()
    {
        char *ptr1 = NULL;
        char *ptr2 = 0;
        printf("\n%d", ptr2);
        strcpy(ptr1, "c");
        strcpy(ptr2, "questions");
        printf("\n%s %s", ptr1, ptr2);
        getch();
    }

     


    A.  printf("\n%d", ptr2);


    B. strcpy(ptr1, "c");


    C. strcpy(ptr2, "questions");


    D. printf("\n%s %s", ptr1, ptr2);


  • Câu 37:

    What will be output of following program?

    #include <stdio.h>
    #include <conio.h>
     
    int main()
    {
        int a = 10;
        void *p = &a;
        int *ptr = p;
        printf("%u\n", *ptr);
        getch();
    }

     


    A.  int a = 10;


    B. void *p = &a;


    C. int *ptr = p;


    D. printf("%u\n", *ptr);


  • Câu 38:

    What will be output of following program?

    #include <stdio.h>
    #include <conio.h>
     
    int main()
    {
        int a = 5, b = 10, c;
        int *p = &a, *q = &b;
        c = p - q;
        printf("%d" , c);
        getch();
    }

     


    A. 3


    B. 4


    C. 5


    D. 6


  • Câu 39:

    What will be output of following program?

    #include <stdio.h>
    #include <conio.h>
     
    int main()
    {
        int i = 5, j;
        int *p , *q;
        p = &i;
        q = &j;
        j = 5;
        printf("%d %d", *p, *q);
        getch();
    }

     


    A.  5 5


    B. Complier Error


    C. 5 Garbage value


  • Câu 40:

    What will be output of following program?

    #include <stdio.h>
    #include <conio.h>
     
    void main()
    {
        int i = 5;
        int *p;
        p = &i;
        printf(" %u %u", *&p , &*p);
        getch();
    }

     


    A. Address of i Address of i


    B. Garbage value Garbage value


    C. Complier Error


  • Câu 41:

    What is output?

    #include <stdio.h>
    #include <conio.h>
    int main()
    {
        int array[2][2][3]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
        printf("%d", array[1][0][2]);
        getch();
    }

     


    A. 6


    B. 7


    C. 8


    D. 9


  • Câu 42:

    What is output?

    #include <stdio.h>
    #include <conio.h>
    void main()
    {
        char arr[8]={'V','I','E','T','N','A','M'}; 
        char *p; 
        p=(char *)(arr+2)[2]; 
        printf("%c", p);  
        getch();
    }

     


    A. I


    B. E


    C. M


    D. N


  • Câu 43:

    What will be output of following program?

    #include <stdio.h>
    #include <conio.h>
    void main()
    {
        char ch[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        int *p = (int*)ch;
        p++;
        printf("%x", *p);
        getch();
    }

     


    A. 37363534


    B. 34353637


    C. 45673333


  • Câu 44:

    What is output?

    #include <stdio.h>
    #include <conio.h>
     
    int main()
    {
        int i = 11;
        int const * p = &i;
        p++;
        printf("%d", *p); 
        getch();
    }

     


    A. 11


    B. 12


    C. Garbage value


    D. Complier error


  • Câu 45:

    Which of the following statements are correct about an array?

    1. The array int num[26]; can store 26 elements
    2. The expression num[1] designates the very first element in the array
    3. It is necessary to initialize the array at the time of declaration.
    4. The declaration num[SIZE] is allowed if SIZE is a macro.


    A. 1,4


    B. 3


    C. 1,2


    D. 1


  • Câu 46:

    The library function used to find the last occurrence of a character in a string is
     


    A. strnstr()


    B. strrchr()


    C. laststr()


    D. strstr()


  • Câu 47:

    What is output? (assuming that the array begins at the location 1002 and size of an integer is 4 bytes)

    #include <stdio.h>
    #include  <conio.h>
    int main()
    {
        int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
        printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
        getch();
    }

     


    A. 1006, 2, 2


    B. 1006, 4, 4


    C. 1002, 5, 5


    D. Error


  • Câu 48:

     What does the following declaration mean?

    int (*ptr)[10];

     


    A. ptr is array of pointers to 10 integers


    B. ptr is a pointer to an array of 10 integers


    C. ptr is an array of 10 integers


    D. ptr is an pointer to array


  • Câu 49:

    What is output?

    #include <stdio.h>
    #include <conio.h>
    int main()
    {
        char str[] = "LAPTRINHC++\0\.NET\0";
        printf("%s\n", str);
        getch();
    }

     


    A. LAPTRINHC++


    B. LAPTRINHC++\0\.NET\0


    C. LAPTRINHC++\0\.NET


  • Câu 50:

    What is output?

    #include <stdio.h>
    #include <conio.h>
    void swap(char *, char *);
     
    int main()
    {
        char *pstr[2] = {"LAPTRINHC++", ".NET"};
        swap(pstr[0], pstr[1]);
        printf("%s%s", pstr[0], pstr[1]);
        getch();
    }
    void swap(char *t1, char *t2)
    {
        char *t;
        t=t1;
        t1=t2;
        t2=t;
    }

     


    A. LAPTRINHC++.NET


    B.  .NETLAPTRINHC++


    C.  Address of pstr[0] Address of pstr[1]


ZUNIA9
AANETWORK