Espacios de nombres
Variantes
Acciones

if statement

De cppreference.com
< c‎ | language

 
 
Lenguaje C
Los temas generales
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Preprocessor
Comentarios
Palabras clave
Tabla ASCII
Las secuencias de escape
Historia de C
Control de flujo
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Sentencias condicionales ejecución
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
if statement
Instrucciones de iteración
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ir declaraciones
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funciones
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaración de la función
especificador inline
Tipos
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los especificadores
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv especificadores
especificadores de clase de almacenamiento
alignas especificador (C99)
Los literales
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expresiones
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
orden de evaluación
los operadores alternativos
los operadores
prioridad de los operadores
Utilidades
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
atributos (C99)
proyecta
Varios
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaje en línea
 
Ejecuta de forma condicional código .
Original:
Conditionally executes code.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Se utiliza cuando el código debe ser ejecutada sólo si una condición está presente .
Original:
Used where code needs to be executed only if some condition is present.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Sintaxis

if ( expression ) statement_true
if ( expression ) statement_true else statement_false

[editar] Explicación

expression deberá ser una expresión, convertible a bool .
Original:
expression shall be an expression, convertible to bool.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si se evalúa como true, se pasa el control a statement_true, statement_false (si está presente) no se ejecuta .
Original:
If it evaluates to true, control is passed to statement_true, statement_false (if present) is not executed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
De lo contrario, el control pasa a statement_false, statement_true no se ejecuta .
Original:
Otherwise, control is passed to statement_false, statement_true is not executed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Palabras clave

if, else

[editar] Ejemplo

#include <stdio.h>
 
int main()
{
    int i = 2;
    if (i > 2) {
        printf("first is true\n");
    } else {
        printf("first is false\n");
    }
 
    i = 3;
    if (i == 3) printf("i == 3\n");
 
    if (i != 3) printf("i != 3\n");
    else        printf("i != 3 is false\n");
}

Output:

first is false
i == 3
i != 3 is false