Skip to content

Instantly share code, notes, and snippets.

@sojohnnysaid
Last active January 19, 2021 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sojohnnysaid/bf48cb2a391a176c0bdfd589503677a3 to your computer and use it in GitHub Desktop.
Save sojohnnysaid/bf48cb2a391a176c0bdfd589503677a3 to your computer and use it in GitHub Desktop.
#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