💩

programierds

Tests
C Beginner 10 min

IF in C

Introductory test to practice basic conditional structures in C.

questions

20

A short tour through if, if-else and nested if to practice reading flow in C.

Tiempo estimado

10:00:00

Avance: 0%

C Beginner 10 min 20 preguntas

IF in C

Introductory test to practice basic conditional structures in C.

Pregunta 1

What is the `if` structure used for in C?

Opciones para What is the `if` structure used for in C?

Pregunta 2

What does this program print?

Snippet c
#include <stdio.h>

int main() {
    int age = 20;

    if (age >= 18) {
        printf("Adult");
    }

    return 0;
}
Opciones para What does this program print?

Pregunta 3

What happens if the `if` condition is false and there is no `else`?

Opciones para What happens if the `if` condition is false and there is no `else`?

Pregunta 4

What does this code print?

Snippet c
#include <stdio.h>

int main() {
    int number = 3;

    if (number > 5) {
        printf("A");
    } else {
        printf("B");
    }

    return 0;
}
Opciones para What does this code print?

Pregunta 5

What is the role of `else` in C?

Opciones para What is the role of `else` in C?

Pregunta 6

What does this program print?

Snippet c
#include <stdio.h>

int main() {
    int x = 10;

    if (x == 10) {
        printf("Equal");
    } else {
        printf("Different");
    }

    return 0;
}
Opciones para What does this program print?

Pregunta 7

Which of the following expressions represents an equality comparison in C?

Opciones para Which of the following expressions represents an equality comparison in C?

Pregunta 8

What does this code print?

Snippet c
#include <stdio.h>

int main() {
    int a = 8;
    int b = 4;

    if (a < b) {
        printf("Smaller");
    } else {
        printf("Greater or equal");
    }

    return 0;
}
Opciones para What does this code print?

Pregunta 9

What is a nested `if`?

Opciones para What is a nested `if`?

Pregunta 10

What does this program print?

Snippet c
#include <stdio.h>

int main() {
    int n = 15;

    if (n > 0) {
        if (n % 2 == 0) {
            printf("Positive and even");
        } else {
            printf("Positive and odd");
        }
    }

    return 0;
}
Opciones para What does this program print?

Pregunta 11

In a nested `if`, what must happen for the inner if to be evaluated?

Opciones para In a nested `if`, what must happen for the inner if to be evaluated?

Pregunta 12

What does this code print?

Snippet c
#include <stdio.h>

int main() {
    int grade = 4;

    if (grade >= 6) {
        printf("Passed");
    } else {
        printf("Failed");
    }

    return 0;
}
Opciones para What does this code print?

Pregunta 13

What does this program print?

Snippet c
#include <stdio.h>

int main() {
    int x = -2;

    if (x > 0) {
        printf("Positive");
    } else {
        if (x == 0) {
            printf("Zero");
        } else {
            printf("Negative");
        }
    }

    return 0;
}
Opciones para What does this program print?

Pregunta 14

Which option best describes the use of braces `{}` in an `if`?

Opciones para Which option best describes the use of braces `{}` in an `if`?

Pregunta 15

What does this code print?

Snippet c
#include <stdio.h>

int main() {
    int age = 17;
    int permission = 1;

    if (age >= 18) {
        if (permission == 1) {
            printf("Can enter");
        } else {
            printf("Cannot enter");
        }
    } else {
        printf("Too young");
    }

    return 0;
}
Opciones para What does this code print?

Pregunta 16

Which operator is used to check if two values are different in C?

Opciones para Which operator is used to check if two values are different in C?

Pregunta 17

What does this program print?

Snippet c
#include <stdio.h>

int main() {
    int x = 0;

    if (x) {
        printf("True");
    } else {
        printf("False");
    }

    return 0;
}
Opciones para What does this program print?

Pregunta 18

What does this program print?

Snippet c
#include <stdio.h>

int main() {
    int x = 5;

    if (x > 0) {
        printf("A");
    }

    if (x < 10) {
        printf("B");
    }

    return 0;
}
Opciones para What does this program print?

Pregunta 19

What does this code print?

Snippet c
#include <stdio.h>

int main() {
    int number = 12;

    if (number > 0) {
        if (number < 10) {
            printf("Positive, single digit");
        } else {
            printf("Positive, two or more digits");
        }
    } else {
        printf("Not positive");
    }

    return 0;
}
Opciones para What does this code print?

Pregunta 20

Which of these snippets correctly represents an `if-else` in C?

Opciones para Which of these snippets correctly represents an `if-else` in C?

Elegi una opcion por pregunta y despues hace click en Revisar resultados.