Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

MindSpace Computers, Yavatmal

An Elite Branch of Disha Computers


C – Language Tricks
----------------------------------------------------------------------------------------------------------------------------------
// C program without using main () function
#include<stdio.h>
#include<conio.h>
#define begin main
void begin ()
{
printf ("Hello Disha Computers");
}
Output: Hello Disha Computers
------------------------------------------------------------------------------------------------------------------------
// Nested printf () statement example
#include<stdio.h>
#include<conio.h>
void main ()
{
int x = 1987;
printf ("%d", printf ("%d", printf ("%d", x)));
}
Output: 198741
Explanation:
o Firstly, innermost (third) printf is executed which results in printing 1987.
o Secondly, middle (second) printf is executed which print total number of digits in 1987
i.e 4.
o Finally, outer (first) printf is executed which print total number of digits in 4 i.e. 1.
------------------------------------------------------------------------------------------------------------------------
// Another nested printf () statement example
#include<stdio.h>
#include<conio.h>
void main ()
{
int x = 247;
printf ("%d", printf ("%d", printf ("%d", x)));
}
Output: 24731
Explanation:
o Firstly, innermost (third) printf is executed which results in printing 247.
o Secondly, middle (second) printf is executed which print total number of digits in 247
i.e 3.
o Finally, outer (first) printf is executed which print total number of digits in 3 i.e. 1.
------------------------------------------------------------------------------------------------------------------------
// Nested scanf () statement example
#include<stdio.h>
#include<conio.h>
void main ()
{
int a;
clrscr();
scanf("%d",scanf("%d",&a));
printf("Value of a is=%d",a);
getch();
}
Output: 24
67
Value of a is=24
Explanation:
o Firstly, second scanf is executed which inputs 24 for variable a.
o Secondly, first scanf is executed which inputs 67.
o Finally, printf is executed which prints value of variable a i.e. 24.
------------------------------------------------------------------------------------------------------------------------
// scanf () inside printf () statement example
#include<stdio.h>
#include<conio.h>
void main ()
{
int a, b, c;
printf ("%d", scanf ("%d %d %d", &a, &a, &b));
}
Output: 23 93 7 (suppose use inputted 3 values for variables a, b and c)
3
Explanation:
o Firstly, scanf is executed which accepts three input from user, for example 23 is
inputted for variable a, 93 is for variable b and 7 for variable c.
o Secondly, printf is executed which print total number of values inputted by scanf i.e.
3. So final output is 3.
==========================================================================

You might also like