Tutorial references

c
c++
c#

Tutorial references

chapters

Basics of C Programming

Simple Program Syntax

first include " #include<stdio.h>" and "#include<conio.h>" header file in top of program.

define main() function.

Example

#include <stdio.h>
#include <conio.h>
void main(){
 clrscr();
 code here
 getch();
}


printf()

It use to display output.

It is the function of stdio.h header file.

syntax:

printf("............");

clrscr()

It use to clear output screen.

Without clrscr() run program more time, you can see previous output data in current output screen. Therefore clrscr() use to clear screen first then display output.

getch()

If you do not use getch() then output screen do not wait for you. Therefore you can not see program output in turbo c++

If you want to wait output screen for you then you can use getch().

Example

#include <stdio.h>
#include <conio.h>

void main(){
 clrscr();
 printf("My first c program.");
 getch();
}

Run program

\n

\n is special type of symbol which has special meaning in c language.

It use to display output from new line.

Bellow example with \n:

Example

#include <stdio.h>
#include <conio.h>

void main(){
 clrscr();
printf("My first c program.\n");
printf("I am going Buxar.");
 getch();
}

Run program

Bellow example without \n:

Example

#include <stdio.h>
#include <conio.h>

void main(){
 clrscr();
printf("My first c program.");
printf("I am going Buxar.");
 getch();
}

Run program

\t

It give blank space horizotly.

signle \t give one tab blank space horizontly.

Bellow example with \t:

Example

#include <stdio.h>
#include <conio.h>

void main(){
 clrscr();
printf("My first c program.\t");
printf("I am going Buxar.");
 getch();
}

Run program

Bellow example without \t:

Example

#include <stdio.h>
#include <conio.h>

void main(){
 clrscr();
printf("My first c program.");
printf("I am going Buxar.");
 getch();
}

Run program

A program with \n and \t

program example:

Example

#include <stdio.h>
#include <conio.h>

void main(){
 clrscr();
 printf("My first c program.\n");
 printf("I am going Buxar.\n");
 printf("I am a student.\t I am reading c.");
 getch();
}

Run program

NOTE: Combination of backslash(\) and character is called "Escape Sequences". It is understand by compilers/interpreters. It is use for special meaning.


Read data from user(console): scanf()

scanf() is a predefine function of stdio.h

It use to read data from user.

You can learn more better in data-type chapter.

Example

#include <stdio.h>
#include <conio.h>

void main(){
 int a;
 clrscr();
 printf("Enter of a: ");
 scanf("%d",&a);/*  & is used before variable name when you want to read data*/
 printf("\n value of a = %d",a);
 getch();
}

Run program

Placeholders

%c used for character

%d used for signed decimal integer

%i used for signed decimal integer

%e used for scientific notation[e]

%E used for scientific notation[E]

%f used for decimal floating point

%o used for unsigned octal

%s used for string of character

%u used for unsigned decimal integer

%x used for unsigned Hexadecimal (lower)

%X used for unsigned Hexadecimal (upper)

%p used for display a pointer

%% used for print a %

Control characters (Escape sequences)

\a - Bell

\n - New line

\r - Carriage return

\b - Backspace

\f - Formfeed

\t - Horizontal tab

\" - Quotation mark

\v - Vertical tab

\' - Apostrophe

\\ - Backslash

\? - Question mark

\0 - Null


About Us

This website(www.sabbla.com) is very useful for beginners and professional developers. Sabbla provides tutorial in simple language. It provides latest technology tutorial which very useful for developers.

See More...

Contact Us

+91 9971366710

+91 9717983128

info@sabbla.com

Buxar, Bihar, India, Pin No.- 802131

Services

Sabbla is providing free latest technology tutorials. All tutorials are free for beginner and professionals.


Terms of Use

sabbla.com is not responsible for any mistake. Users can inform to sabbla.com for any mistake. But sabbla.com always try for 0-0 mistake.

Privacy policy

Currently sabbla.com does not collect any data from users.

                   

copyright © 2017-2018