Formatted input/output statement

1)      printf() :- printf() is a inbuilt function that is responsible to display contents or statement on monitor as a following format:-
Syntax:- To display contents/ statements on monitor
printf(“contents”);
 
 

NOTE:- (i) Statements or contents must be enclosed within double quotes.
                (ii)An inbuilt function printf reside into header file stdio.h.
Example:- Write a program to display a message “Welcome to C “ on standard output device i.e monitor.
soln                             void main()
                                {
                                clrscr();
                                printf(“Welcome to C”);
                                getch();
                                }
Output-------- Welcome to C
2)      scanf():-Accepting vaues from keyboard
The C compiler provides an inbuilt function named scanf() i.e used as a following format to accept values from keyboard.
Syntax:- To accept values from keyboard
printf(“message prompt”);
scanf(“format specifier”,&variable name);
 
 


                                                                                                                                                                       
NOTE:-  (i) In a scanf a format specifier ensure total number and types of values required from keyboard.
       (ii)Ampersand(&) operator is specially used for drop an address of variable.
Example:- void main()
                        {
                        int a=10;
                        clrscr();
                        printf(“Value of a= %d”,a);
                        printf(“\n address of a=%u”,&a);
                        getch();
                        }
Output-------à         value of a= 10
                                                Address of a = 65524

3)      comma(,):- A comma is used as following 2 bit:-
(i)                  Use as a separator
(ii)                Use as operator
(i)                  Use as a separator:- A comma is used as a following way to separate more than one values in single line.
Example:- int a,b,c;
[Here comma separate 3 integer type variable.]
(ii)                Use as a operator:- When comma(,) is used as an operator then it perform an operation as a following way:-
a)      It performs an operation left to right.
b)      It returns value of last statement.
Example:- int a=10,r;
     (a)    r= a,a=20,++a;
printf(“r=%d,a=%d”,r,a);
Output-------------à r=10,a=21
     (b)   r= (a,a=20,++a);
printf(“r=%d,a=%d”,r,a);
Output-------------à r=21,a=21
     (c)    r= printf(“\n %d”,printf(“wel”),printf(“\ncome”)));
printf(“\nr=%d”,r);
Output---------à wel
                                come
                                5
                                r=2
     (d)   r=(printf(“come”,printf(“wel”));
printf(“\nr=%d”,r);
Output---------à comewel
                r=3

     (e)   printf(“%d\n%d”,printf(“Welcome\n%s%c”,”To”,’C’),printf(“Frndzone”),printf(“Education”)));
printf(“\nr=%d”,r);
Output-------------à FrndzoneEducationWelcome
                                        ToC11
                                        9
                                         r=4


Comments

Popular Posts