01 Intro
Basics¶
Digital data is in binary form.
- 0/1 (bit)
- 8 bits = 1 byte
- 1024 bytes = 1KB
When write a C program to perform a task, it gets converted into binary instructions which a computer can understand
Variables¶
Tokens¶
-
atomic unit of a code
-
Key words
-
Identifiers
Code Block¶
group of code within { ... }
Structure¶
#include <stdio.h>
void print_on_screen()
{
printf("hi"); // ; = terminator
}
int main() // driver function of your program
{
// code
print_on_screen();
int x = 4; //
return 0;
}
Data Types¶
Primitive¶
void | (nothing) | 0 | |
boolean | True/False true/false | 1 | |
char | ‘H’ | 1 | %c |
int | 34444 | 2 | %d |
float | 334545.345534 | 4 | %f |
double | 334545345534334545345534.334545345534334545345534 | 8 | % |
User-defined¶
(not in scope of current exam)
Math Operators¶
\[ + - * / \% \]
-
int
/int
=int
-
B
- ^
- Multiplication/Division (whichever comes first)
- Addition/Subtraction (whichever comes first)
Type Casting¶
change in data type of a variable for a momentary purpose
implicit (automatic)
int/int \(\to\) int
- 3/2 = 1.5
- 3/2 = 1
int/float \(\to\) float
- larger data type
explicit(user-defined) type casting
Relational Operators¶
\[ > , \ge , < , \le, ==, \ne, != \]
- \(=\) and \(==\)
- assignment
- equality operator
Logical Operators¶
\[ ! \\ \&\& \\ || \]
\[ [!0 \&\& 1 || 3\&\&!1] \]
int main()
{
int x;
// take input from user
scanf("%d", &x); // storing the value in the address of x
printf("%d", x);
return 0;
}
// x = 5