The meaning for the word “void” is “nothing or completely empty”. This term plays a vital role in computerprogramming. The most familiar uses are:
- Void as a Function Return Type
- Void as a Function Parameter
- Void as a Pointer Declaration
Examples:
- Void as a Function Return Type
void maxval (int a,int b);
void main()
{ int x=6,y=10;
clrscr();
maxval(x,y);
getch();
}
void maxval(int a,int b)
{ if(a>b)
{
printf(“\na=%d is greater value”,a);
}
else
{
printf(“\nb=%d is greater value”,b);
}
}
- Void as a Function Parameter
int sum(void); //function declare//
void main()
{ int ans;
clrscr();
ans= sum();
printf(“%d”,ans);
// printf(“ans is %d”, sum()); //function call//
getch();
}
int sum(void)//function defintion//
{
int a,b,c;
printf(“enter the value of a,b”);
scanf(“%d%d”,&a,&b);
c=a+b;
return c;
// printf(“\n your addition is=%d”,c);
}
- Void as a Pointer Declaration
- int main()
- {
- int a = 10;
- void *ptr = &a;
- printf(“%d”, *(int *)ptr);
- return 0;
- }
- OUTPUT:
- 10
TCCI Computer Coaching teaches various Languages like ,C, C++, Java, Python, Database Management, Python, Data Structure HTML,CSS, Java Script, .Net , PHP, System Programming Compiler Design, Boot Strap, Angular Js etc.
For more information about TCCI in Bopal and Satellite in Ahmedabad.
call us@9825618292.
visit us@tccicomputercoaching.com