filmov
tv
difference between printf and scanf in c
![preview_player](https://i.ytimg.com/vi/Qb_KEmoHBbs/maxresdefault.jpg)
Показать описание
In this Video Lesson I am gonna show you how to print any value in C Programming Language and How to get input from the user,
what is Printf() function ?
What is scanf() function?
how to write first programming in C Language.
Write hello world program in c.
Let's Start
First , we need to add header file such as include studio.h and
include conio.h
then
start main writing main() function
inside the main function use clrscr () function it is used to clear output screen's previous data
and at the end of the program we use getch () function , basically getch () function is all about to get input character from the user but here we use it for holding the output screen until user press any key.
printf () is very simple to use if you want to print any constant string, just pass string in double quotes "" like printf("Hello world");
it will show the message on output screen.
if you want to print any variable value you have to use format specifier such as I have int value
int x = 10;
to print this x
printf ("%d",x); this way you can print any variable values the only things which you have to know is Format Specifier Chart such as
Data Type Format Specifier
short %d
int %d
float %f
double %lf
char %c
string %s
Now, How to get input from the user, it also very simple c designer has already given us such predefined functions which we need not bother about such type of actions , it is scanf() function it takes two arguments
first format specifier
second variable to hold the scanned value
and the syntax is
int x; I want to scan value to x
scanf ("%d", &x);
now the question is why we use & before variable while scanning it is because we have to tell the compiler the exact location of the corresponding variable .
& is used to get address of a variable .
You can also check more tutorials from
LEARN COMPLETE WEB DESIGNING COURSE
Lesson 1 : Intro to complete Complete Training
Lesson 2 : Milestone of HTML
Lesson 3 : Format Tags
Lesson 4 : Image & Marquee Tags
Lesson 5 : Table & Inputs Tags
what is Printf() function ?
What is scanf() function?
how to write first programming in C Language.
Write hello world program in c.
Let's Start
First , we need to add header file such as include studio.h and
include conio.h
then
start main writing main() function
inside the main function use clrscr () function it is used to clear output screen's previous data
and at the end of the program we use getch () function , basically getch () function is all about to get input character from the user but here we use it for holding the output screen until user press any key.
printf () is very simple to use if you want to print any constant string, just pass string in double quotes "" like printf("Hello world");
it will show the message on output screen.
if you want to print any variable value you have to use format specifier such as I have int value
int x = 10;
to print this x
printf ("%d",x); this way you can print any variable values the only things which you have to know is Format Specifier Chart such as
Data Type Format Specifier
short %d
int %d
float %f
double %lf
char %c
string %s
Now, How to get input from the user, it also very simple c designer has already given us such predefined functions which we need not bother about such type of actions , it is scanf() function it takes two arguments
first format specifier
second variable to hold the scanned value
and the syntax is
int x; I want to scan value to x
scanf ("%d", &x);
now the question is why we use & before variable while scanning it is because we have to tell the compiler the exact location of the corresponding variable .
& is used to get address of a variable .
You can also check more tutorials from
LEARN COMPLETE WEB DESIGNING COURSE
Lesson 1 : Intro to complete Complete Training
Lesson 2 : Milestone of HTML
Lesson 3 : Format Tags
Lesson 4 : Image & Marquee Tags
Lesson 5 : Table & Inputs Tags
Комментарии