Basics
Basics
C prog
C Basic Commands
C is a compiled language. A compiler is a special tool that compiles the program and converts it
into the object file which is machine readable.
After the compilation process, the linker will combine different object files and creates a single
executable file to run the program.
The following diagram shows the execution of a ʻCʼ program
Following is the list of popular compilers available online:
•Clang compiler
•MinGW compiler (Minimalist GNU for Windows)
•Portable ʻCʼ compiler
•Turbo C
First C Program
printf() function
The printf() function is used for output. It prints the given statement to the
console
printf(“Msg”);
printf("format string",argument_list);
The format string can be %d (integer), %c (character), %s (string), %f (float) etc
scanf() function The scanf() function is used for input. It reads the input data
from the console
scanf("format string",argument_list);
#include<stdio.h>
int main()
{
int number;
printf("enter a number:");
scanf("%d",&number);
printf("cube of number is:%d ",number*number*number);
return 0;
}
Variables Variables are containers for storing data values.
5.ʻCʼ is a case sensitive language that means a variable named ʻageʼ and ʻAGEʼ are
different.
Following are the examples of valid variable names in a ʻCʼ program:
height or HEIGHT
_height
_height1
My_name
1height
Hei$ght
My name
Data Types in C
It specifies the type of data that the variable can store like
integer, character, floating, double, etc.
Basic Data Types the most basic ones:
int main()
{
double dNum = 99.99; // Double (floating point number)
printf("%lf", dNum);
return 0;
}
Format Minimal
Size Of Data Types In C Data Type Size in bit
Specifier Range
-32,767 to
int %d, %i 16 or 32
32,767
-2,147,483,64
7 to
long int %ld, %li 32
2,147,483,64
7
1E-37 to
1E+37 along
float %f with six digits 32
of the
precisions
1E-37 to
1E+37 along
double %lf with six digits 80
of the