Skip to content

Instantly share code, notes, and snippets.

@sojohnnysaid
Last active January 19, 2021 22:49
Embed
What would you like to do?
#include <stdio.h>
int main(void){
// Example 2: conditional structures.
int answer = 42;
if (answer == 42) //Only runs the line below if true
printf("You have found the answer! It is %d\n\n", answer);
else // Only runs the line below if false
printf("WRONG!!!!");
//----------------------------------
// Example 2: conditional structures
// Notice the next conditional has curly brackets
// between the execution blocks.
// This is because multiline blocks of code need to be wrapped
// while a single line statment does not require the curly brackets
if (0){
printf("one\n");
printf("two\n");
}
else if(1){
printf("three\n");
printf("four\n");
}
else{
printf("no more numbers!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment