CODE:
#include<stdio.h>
#include<conio.h>
void wish()
{
printf("\nHello ");
}
#pragma startup wish
/*this preprocessor statement make wish()
get first executed before main()*/
void main()
{
printf("Coder!");
getch();
}
OUTPUT:
Hello Coder!
Coding Tricks
Sunday, 17 July 2011
Program to print line number and filename
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Line %d of %s",__LINE__,__FILE__);
getch();
}
OUTPUT:
Line 7 of ..\..\CPROGRAM.C
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Line %d of %s",__LINE__,__FILE__);
getch();
}
OUTPUT:
Line 7 of ..\..\CPROGRAM.C
To create a variable that takes only 3 bits memory
CODE:
#include<stdio.h>
#include<conio.h>
struct abc
{
clrscr();
st.xyz = 7; //(1112)
printf("\nValue of xyz(before increment) : %d",st.xyz);
st.xyz++;
printf("\nValue of xyz(after increment) : %d",st.xyz);
getch();
}
OUTPUT:
Value of xyz(before increment) : 7
Value of xyz(after increment) : 0
#include<stdio.h>
#include<conio.h>
struct abc
{
unsigned xyz : 3; //takes 3 bit memory
}st;
void main()
{
clrscr();
st.xyz = 7; //(1112)
printf("\nValue of xyz(before increment) : %d",st.xyz);
st.xyz++;
printf("\nValue of xyz(after increment) : %d",st.xyz);
getch();
}
OUTPUT:
Value of xyz(before increment) : 7
Value of xyz(after increment) : 0
Subscribe to:
Comments (Atom)