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/619fdfb586960b8f0009d8b7afb3e150 to your computer and use it in GitHub Desktop.
Save sojohnnysaid/619fdfb586960b8f0009d8b7afb3e150 to your computer and use it in GitHub Desktop.
Example of how variables work in C
#include<stdio.h>
int main(void){
// Example of using variables to hold data
int number = 90;
char string[] = "That is a great score";
char letter = 'A';
printf("Your score was %d%%! %s! You're an %c student!\n\n", number, string, letter);
printf("Putting some new data in our variables...\n\n");
number = 80;
// Array's are immutable (even if the exact same string!)
// this line of code will cause errors in compilation
// string = "That is a great score";
char new_string[] = "That is a pretty good score";
letter = 'B';
printf("Your score was %d%%! %s! You're a %c student!\n\n", number, new_string, letter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment