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. The...

Array in C Language Btech Bca Notes

 Array in C Language Btech Bca Notes An array is a data form that can hold several values all of the same type. An array is a collection of variable of the same type that are referral to by a common name. Also Read:   Beginner our view on C programming Language  . Array are vital for most programming language. They are collection of variables, which we call elements. Each of the element in an array is stored sequentially in the computeric memory.  This making it easy to  m anipulate them and navigate among them. Since all the elements in an array are of same type, array allows us to represent a group of similar elements as an ordered  sequence  and work on them as a whole (grouping together related data). Array organize data in such a way that it can be easily sorted. To create an array, we use a declaration statement. An array declaration should indicate three things: 1. The type of value to be stored in each element. 2. The name of the array. 3. The ...