C Declare Multiple Variables
Declare Multiple Variables To declare more than one variable of the same type, use a comma-separated list: Example int x = 5, y = 6, z = 50; printf(“%d”, x + y + z);
Declare Multiple Variables To declare more than one variable of the same type, use a comma-separated list: Example int x = 5, y = 6, z = 50; printf(“%d”, x + y + z);
Change Variable Values If you assign a new value to an existing variable, it will overwrite the previous value: Example int myNum = 15; // myNum is 15 myNum = 10; // Now myNum is 10 You can also assign the…
Format Specifiers Format specifiers are used together with the printf() function to tell the compiler what type of data the variable is storing. It is basically a placeholder for the variable value. A format specifier starts with a percentage sign…
Variables are containers for storing data values, like numbers and characters. In C, there are different types of variables (defined with different keywords), for example: int – stores integers (whole numbers), without decimals, such as 123 or -123 float –…
Comments in C Comments can be used to explain code, and to make it more readable. It can also be used to prevent execution when testing alternative code. Comments can be singled-lined or multi-lined.
New Lines To insert a new line, you can use the \n character: Example #include <stdio.h> int main() { printf(“Hello World!\n”); printf(“I am learning C.”); return 0; } You can also output multiple lines with a single…
Output (Print Text) To output values or print text in C, you can use the printf() function: Example #include <stdio.h> int main() { printf(“Hello World!”); return 0; }
Statements A computer program is a list of “instructions” to be “executed” by a computer. In a programming language, these programming instructions are called statements. The following statement “instructs” the compiler to print the text “Hello World” to the screen:
Syntax You have already seen the following code a couple of times in the first chapters. Let’s break it down to understand it better: Example #include <stdio.h> int main() { printf(“Hello World!”); return 0; }