QCM en programmation C – Les Constants – Partie 1

QCM sur C avec des réponses pour la préparation des entretiens, des tests en ligne, des examens etc.

 
 

1. Quelle est la sortie de ce code C?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
int main()
{
enum {FRAISE = 6, BANANE, POMME = 2, AUBERGINE};
printf("AUBERGINE = %d\n", AUBERGINE);
}
#include <stdio.h> int main() { enum {FRAISE = 6, BANANE, POMME = 2, AUBERGINE}; printf("AUBERGINE = %d\n", AUBERGINE); }
#include <stdio.h>

int main()
{
     enum {FRAISE = 6, BANANE, POMME = 2, AUBERGINE};
     printf("AUBERGINE = %d\n", AUBERGINE);
}

A AUBERGINE = 3

B AUBERGINE = 2

C AUBERGINE = 6

D AUBERGINE = 7

2. Quelle est la sortie de ce code C?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
int main()
{
printf("programmation C %s", "Fonction par \n%s WayToLearnX", "WWW");
}
#include <stdio.h> int main() { printf("programmation C %s", "Fonction par \n%s WayToLearnX", "WWW"); }
#include <stdio.h>

int main()
{
     printf("programmation C  %s", "Fonction par \n%s WayToLearnX", "WWW");
}

A

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Programmation C Fonction par
WWW WayToLearnX
Programmation C Fonction par WWW WayToLearnX
Programmation C Fonction par
    WWW WayToLearnX

B

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Programmation C Fonction par\n%s WayToLearnX
Programmation C Fonction par\n%s WayToLearnX
Programmation C Fonction par\n%s WayToLearnX

C

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Programmation C Fonction par
%s WayToLearnX
Programmation C Fonction par %s WayToLearnX
Programmation C Fonction par
    %s WayToLearnX

D Erreur de compilation

3. Le pointeur « str » contient une référence vers quelle chaîne de caractére ____?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
char * str = "Hello\0" "World!";
char * str = "Hello\0" "World!";
char * str = "Hello\0" "World!";

A Hello

B Hello\0world!

C Helloworld!

D Déclaration invalide

 

4. Quelle est la sortie de ce code C?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
#define x 20
int main()
{
const int x = 7;
printf("x = %d\n", x);
}
#include <stdio.h> #define x 20 int main() { const int x = 7; printf("x = %d\n", x); }
#include <stdio.h>
#define x 20

int main()
{
    const int x = 7;
    printf("x = %d\n", x);
}

A x = 7

B x = 20

C Erreur de compilation

D Erreur d’exécution

5. Quelle est la sortie de ce code C?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
int main()
{
int x = 010;
printf("%d", x);
}
#include <stdio.h> int main() { int x = 010; printf("%d", x); }
#include <stdio.h>

int main()
{
    int x = 010;
    printf("%d", x);
}

A 2

B 8

C 9

D 10

6. Quelle est la sortie de ce code C?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
enum oiseau {MOINEAU, PERROQUET, PAON};
enum animal {LION = 16, LAPIN, ZEBRE, TIGRE};
int main()
{
enum oiseau o = LION;
int k;
k = o;
printf("%d\n", k);
return 0;
}
#include <stdio.h> enum oiseau {MOINEAU, PERROQUET, PAON}; enum animal {LION = 16, LAPIN, ZEBRE, TIGRE}; int main() { enum oiseau o = LION; int k; k = o; printf("%d\n", k); return 0; }
#include <stdio.h>

enum oiseau {MOINEAU, PERROQUET, PAON};
enum animal {LION = 16, LAPIN, ZEBRE, TIGRE};

int main()
{
        enum oiseau o = LION;
        int k;
        k = o;
        printf("%d\n", k);
        return 0;
}

A 0

B Erreur de compilation

C 1

D 16

7. Quelle est la sortie de ce code C?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
#define MAX 3
enum animal {LION = MAX + 1, LAPIN = LION + MAX};
int main()
{
enum animal a = LAPIN ;
printf("%d\n", a);
return 0;
}
#include <stdio.h> #define MAX 3 enum animal {LION = MAX + 1, LAPIN = LION + MAX}; int main() { enum animal a = LAPIN ; printf("%d\n", a); return 0; }
#include <stdio.h>
#define MAX 3

enum animal {LION = MAX + 1, LAPIN = LION + MAX};

int main()
{
    enum animal a = LAPIN ;
    printf("%d\n", a);
    return 0;
}

A erreur de compilation

B 7

C valeur non définie

D 3

8. Quelle est la sortie de ce code C?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
#include <string.h>
int main()
{
char *str = "y";
char c = 'y';
char array[1];
array[0] = c;
printf("%d %d", strlen(str), strlen(array));
return 0;
}
#include <stdio.h> #include <string.h> int main() { char *str = "y"; char c = 'y'; char array[1]; array[0] = c; printf("%d %d", strlen(str), strlen(array)); return 0; }
#include <stdio.h>
#include <string.h>

int main()
{
    char *str = "y";
    char c = 'y';
    char array[1];
    array[0] = c;
    printf("%d %d", strlen(str), strlen(array));
    return 0;
}

A 1 1

B 2 1

C 2 2

D 1 (valeur indéfinie)

4 réflexions sur “QCM en programmation C – Les Constants – Partie 1

  • juillet 21, 2020 à 2:04 am
    Permalien

    La réponse à la question 3 est A

    Répondre
  • juillet 23, 2020 à 5:25 pm
    Permalien

    Je comprends pas la réponse de la question 3. Comment se fait il que la réponse ne soit pas A ?

    Répondre
  • juillet 23, 2020 à 5:57 pm
    Permalien

    Pouvez vous revérifier la réponse à la question 8 car je pense que c’est D.

    Répondre

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *