C programming Cheatsheet...

Syntax (Boilerplate Code) :

int main()

printf() : printf() function for used to show the output.


scanf() : scanf() function for used to take the input from users.

scanf("format_specifier", &variable);

Comments : A comment is not executed by the compiler. The comments is used for the increase the readability. In c programming language two types of comments.

1. Single Line comment

// This is single Line Comment

2. Multi Line comment

/* This is 
Multiple line 

Data type : Datetype is the type of data to declare the variable.

Integer Type

int variable_name;

Character Type

char var;

Float Type

float var_name;

Double Type

double variable_name;

Void Type


Escape Sequences : It is a sequence of characters starting with a backslash, and it doesn't represent itself when used inside string literal.

Beep / Alarm : It produce the beep sound.


backspace : Add backspace


New Linke : Add New line


Carriage return 


Tab : Gives the tab space


Backslash : Add backslash


Single Quote : Add single quotation mark.


Question Mark : Add question mark 


Octal Number : It represents the value of an octal number


Hexadecimal Number : It represents the value of an Hexadecimal number.


Null : The null character is usually used to terminate a string.


Conditional Instructions

Conditional Statement is used to perform the logical opertion in program.

if statement

if(/* condition */){
   /* statement; */

if-else statement

if(/* condition */){
    /* statement*/
    /* statement */

if-else-if-else statement

    /* statement */
else if(/* condition */){
    /* statement */
/* statement */

 Switch Statement

    case 1 :
    case 2 :
        /* statement */
    default :
        /* default statement */

Loops : 

Loops is used for , the line of code execute repatedly then programmer used loops.

for loop

for(/*initialization*/ ; /*condition*/; /*increament/decrement*/)
    /* code*/

while loop


do while loop

    /* code */

break statement : break keyword inside the loop is used to terminate the loop.


continue statement : continue keyword skips the rest of the current iteration of the loop and returns to the starting point of the loop.


Function and Recursion : Function are used to divide the program in pieces and used function many times in our program.

Function Defination

return_type name_function(data_type parameter ...){
    // Code of the function

Recursion : Recursion is when a function calls itself to solve the problem. Which function is calls itself called the recursive function.

void fun(){
    ... ... .. 
    ... ... ..

Pointers : Pointer is the variable which contains the address of the another variable.

data_type = *variable_name;

Array : Array is the collection of the same datatypes.

data_type array_name[array_size];

Access Element 


String : 

A string is a 1-D character Array terminated by a null character('\0')


char string_name[string_size];

gets() function : It allows to enter the multi-word string.


puts() function : It used to show the string.


strlen() function : It is used for to calculate the length of string.


strcpy() function : It is used for copy the string to another one.

strcpy(destination, source);

strcat() function : It is used for concatenate two string.

strcat(first_string, second_string);

strcmp() function : It is used for campare two string.

strcmp(first_string, second_string);

Structure : 

The Structure is a collection of different types of variable in a single. Define structure means creating a new data type.

Syntax :

struct structure_name
    datatype member1;
    datatype member2;
    ... .... ...

typedef keyword : typedef function allows user to provide alternative names for the primitive and user-defined data type.

typedef struct structure_name
    datatype member1;
    datatype member2;
    ...   ...  ...



struct structure_name
    datatype member1;
    datatype member2;
    ...   ...  ...

typedef structure_name new_name;

File Handling

File handling in C enables us to create, update, read, and delete the files stored on the local file system through our C program.

FILE pointer

FILE *filepointer;

Opening a file : It is used to open file in C.

filePointer = fopen(filename.txt,w);

fscanf() function : It is used to read the content of file.

fscanf(FILE *stream, const char *format, ...);

fprintf() function : It is used to write content into the file.

fprintf(FILE *fptr, const char *str, ...);

fgetc() function : It reads a character from a file opened in read mode.

fgetc(FILE *pointer);

fputc() function : It writes a character to file opened in write mode.

fputc(char, FILE,*pointer);

Closing a File : It close the file.


Dynamic Memory Allocation 

The concept of dynamic memory allocation in c language enables the C programmer to allocate memory at runtime.

malloc() function : 

ptr = (TypeCast*)malloc(size());

calloc() function :

ptr = (TypeCase*)calloc(n,size);

free function : 


realloc() function : 

ptr = realloc(ptr, x);


Please Do comment and gives your Suggestion.



Login is mandatory to comment Please login

 Akash Kumar

Comment : Post is very helpful!!