Skip to main content

Format Specifier In C Programming Btech BCA Notes

 

 Format Specifier In C Programming Btech BCA Notes

Format Specifier In C Programming

Welcome, Hope you are doing well. Today we are talking about Foramat specifier in C language. We can also say Type Specifier In C. 

So, Today we are read formate specifier as well as printf and scanf Formats in different situations and different conditions.

Before you read this article May you also like our previous posts:- 

 Beginner our view on C programming Language 

 Structure Of C Language Program

 Variables & Datatypes In C Language . It may help you to boost Your Information.

In C Programming language, Types specifier is a special piece of code which is used during the input and output. Type specifier inform the compiler about the type of data which will be entered or displayed during an input output operation. Input mans reading data from keyword while output means displaying data either on screen or a printer.

In c – Language every datatype has its own type specifier:

Name size Type Specifier
Int 2 %d
Char 1 %c
Long 4 %ld
Double 8 %lf
Float 4 %f
Long Double 10 %Lf

* Type specifier are used while performing formatted input / output

* Input can be through keyboard only and output monitor printer.

* This type of specifier is not used to print simple English statement.

                       Eg : Hello / Etc                        

formatted input ouput

Handling Input / Output In C Language

Handling Input / Output In C Language

Printf(print Formatted)


Printf (print formatted) in C

Printf is a formatted output function provide by ‘stdio.h’ header file. Printf() writes the data to the ‘stdout stream’. Printf() can be used to display a string or value of variable of any primitive type.

Printf() formats the data according to the formate specifier. Printf() is the the most versatile method of displaying output on screen.

Syntax :-      

printf(“….string lines….”);

The first form of printf() is used to display a string. Provide the string in double codes.

For Eg :-        

printf(“Hello and Welcome”);

syntax:-

printf(“….type specifier….”, variable name);

The Second form of printf() is used to display value of variable. Whenever value of variable is to be display, we first specifie the type specifier of the variable and then after a, We specifie the variable name.

For Eg :-

Int a=100;

Int b=200;

Int c= a+b;

Printf(“%d”,c);

Various use of printf

·        A single printf can be used to print multiple variables. This done by providing n-types specifiers followed by equal number of variables.

     Syntax :


Printf(“type specifier 1, type specifier 2…type specifier n, variable name 1, variable name 2,... variable name n);

      For Ex :   suppose our output is 10 20 . We take a=10 & b=20, So we print them as   below.


 int a=10;
 float b=20;
 printf(“%d,%f”, a,b);

·        Printing a string and a value of variable together.

      Output:- The sum of 10 and 20 = 30 {Where:-  a=10 b=20 c=30}

      Code:-    

 

printf(“The sum of %d and %d=%d”,a,b,c);

    We can print value of a variable and a string by specifying the string and type specifier both in the double codes.

    After double codes apply a comma and then supply list of variable whose value is to be printed.

    Output:-  10*5=50  { where a=10 b=5 & c=50 }

    Code:-     

   

printf(“%d*%d=%d”, a,b,c);

 

Output:- The sq of 8=64.thanks

Code:-    

printf(“The sq of %d=%d.thanks”,a,b);

Scanf (scan formatted)

Scanf (scan formatted)

Scanf() is a formatting function which is part of ‘stdio’ header file. Scanf() reads input item from the ‘stdin stream’. Scanf() can read data of any primitive type.

Syntax :-       

scanf(“….type specifier….”,&variable name);

Scanf() accepts two arguments. The first argument is the type specifier of the variable to be printed. The second argument is the variable name.

For Eg :-

Int x;

Printf(“enter a number”);

Scanf(“%d”,&x);


Various use of scanf

 ·       Using scanf to fetch multiple value :-h6yn 04 n

Syntax :-

Scanf(“type specifier”, &variable name);

Ex :- fetch multiple value

int x;

Float y;

Scanf(“%d%f”, &x,&y);

A single scanf can be used to read multiple values. To do so, first provide the required number of    type specifiers in double codes and then provide a comma. After the comma supply a list of variables in which value is to be stored.

Syntax :-

Scanf(“type specifier 1  type specifier 2... type specifier n”, &var1, &var2,…&var n);

For Ex :-

Float d;

Double a;

Scanf(“%f%lf”,&d,&a);

Sample Code:-

//Area of Rectangle

#include<conio.h>

#include<stdio.h>

void main()

{

int l,b,r:

clrscr();

printf(“enter l and b”);

scanf(“%d”,&l,&b);

r=l*b;

printf(“the area is %d”,r);

getch();

}

    

We will going on series of C Programming language of all topics. So, you can follow us for more updates.   


Comments

Popular posts from this blog

Control Statements in c language

So, Today we are going on new topic name control statements in C language. In which we read Looping(For, While and Do While), Jumping(Break, goto and Continue) and Decision Control statements(Switch, If, If Else and  If else if ladder)  in C. Before you read this article May you also like our previous posts :-    Structure Of C Language Program   Variables & Datatypes In C Language    Format Specifier In C Programming  .   It may help you to understanding it. A Statement is the smallest unit that is a complete instruction in itself statements contains expression and usually end with a semicolon. Statements are of two Types:- Types of Statements in C  1. Sequential Statement   2. Control Statement Sequential Statements are statements which are executed by one in sequential manner. Control Statements are the statements which alter the flow of execution and provide better control to the programme. On the flow of execution. They are useful to write better and complex program. Control S

Beginner our view on C programming Language

  Beginner our view on C programming Language   Beginner ourview on C programming Language History about C programming Language. The founder or we can say developer of C programming language was Dennis Ritchie. He was found in  Bell labs USA. The Birth of C language is originally on 1972. After the time C is widely popular all around the world. C is also used in to develop many OS system some are Linux and Windows. Now days C is still widely used or popular language in Programming world. Here, we have a question is What is a Program ?  A Program is a set of instruction which on   execution by a machine produces a specific result. A machine needs set of instructions to perform an operation. Those set of instruction are contained in a program. What is program? What is Programming languages ? What Is a Programming Languages? Meaning- A programming language allows a programmer to develop instructions which can be executed by a machine. A programming language acts as an intermediate bet

Whatsapp chats and Status tricks 2021

whatsapp chatting and status trick Today we will talk about some secret options of WhatsApp which you should know. We will talk about how we can see someone's Whatsapp status without anyone knowing it. And at the same time, we will also talk about how to see someone's message, without getting blue ticked in his phone. To know about all this, read this entire article carefully.  1.  Let's know about Whatsapp In the whole world, whatsapp is the only messenger application to be used the most. WhatsApp is a free application that anyone can use for absolutely free. We do not see any advertisement like other social media applications, meaning It does not earn any money from its own app. WhatsApp was created by Brian Acton and Jan Koum in 2009. After 2014 facebook bought whatsapp, since then it is now owned by facebook. WhatsApp is now controlled and maintained by facebook. As you may know, Facebook is a multinational company. There are many products of Facebook which we use every