fundamentals-of-c
fundamentals-of-c
FUNDAMENTALS OF
C
Basics of C Programs
A C program basically consists of the following parts
Preprocessor Commands
Functions
Variables
Statements & Expressions
Comments
C header files : Header files are helping file of your C program which holds the
definitions of various functions and their associated variables that needs to be
imported into your C program with the help of pre processor #include statement.
All the header file have a '.h' an extension that contains C function declaration
and macro definitions.
The default header file that comes with the C compiler is the stdio.h.
Syntax:
#include <file>
Basics of C Programs
(cont..)
Variables: In programming, a variable is a container (storage area) to hold data.
To indicate the storage area, each variable should be given a unique name
(identifier).
Example: int playerScore = 95;
Here, myVar is a variable of int (integer) type. The size of int is 4 bytes.
C Data Types (cont..)
Type Size (bytes) Format Specifier
int at least 2, usually 4 %d
char 1 %c
float 4 %f
double 8 %lf
short int 2 usually %hd
unsigned int at least 2, usually 4 %u
long int at least 4, usually 8 %li
long long int at least 8 %lli
unsigned long int at least 4 %lu
unsigned long long int at least 8 %llu
signed char 1 %c
unsigned char 1 %c
long double at least 10, usually 12 or 16 %Lf
C Programming Operators
An operator is a symbol that operates on a value or a variable.
For example: + is an operator to perform addition.
Associativity of Operators
The associativity of operators determines the direction in which an expression is
evaluated. For example,
b = a;
C Input Output (I/O)
C Output
In C programming, printf() is one of the main output function. The function
sends formatted output to the screen. For example,
Example : C
Output #include
<stdio.h> int main()
{
printf("C Programming");
return 0;
}
C Input Output (I/O) (cont..)
C Input
In C programming, scanf() is one of the commonly used function to take input
from the user. The scanf() function reads formatted input from the standard
input such as keyboards.