Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Keep The TechnoWorldInc.com Community Clean: Read Guidelines Here.
Recent Updates
[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[February 14, 2024, 02:00:39 PM]

[February 14, 2024, 02:00:39 PM]

[February 14, 2024, 02:00:39 PM]

[February 14, 2024, 02:00:39 PM]

[February 08, 2024, 10:26:18 AM]

[February 08, 2024, 10:26:18 AM]

[February 08, 2024, 10:26:18 AM]

[February 08, 2024, 10:26:18 AM]

[November 27, 2023, 06:32:12 PM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » C/C++/C#
 How To Make Efficient C Program Part-II
Pages: [1]   Go Down
  Print  
Author Topic: How To Make Efficient C Program Part-II  (Read 3056 times)
Taruna
Elite Member
*****



Karma: 13
Offline Offline

Posts: 845

Hi ALL


View Profile
How To Make Efficient C Program Part-II
« Posted: January 03, 2007, 01:46:40 PM »


C supports a special kind of pointer known as void pointer.
It s a generic pointer means it can be used for storing
any type of pointer(int,float,char etc).We can reduce complexity
and number of pointer using void pointer.

We can declare a pointer as void as we declared any
other pointer.E.g-void *ptr;

Advantage:i)Intialistining any pointer of any type.
ii)No type casting is require while intializing.
iii)it s may useful when data type is unknown.
iv)We can assign a void pointer to another non void pointer.

Disadvantage:i)No arithmetic operation is not possible in void pointer.


Use of void pointer-


#include <stdio>
#include<conio>
void call(void *ptr);
/*function prototype*/

void main()
{
float f=90.88;
int i=80;
void *vptr;
clrscr();

printf(" Before Vpointer(integer)=%d",i);
call(&i);
printf(" After Vpointer(integer)=%d",i);

printf(" Before Vpointer=%.2f",f);
call(&f);
printf(" After Vptr=%.2f",f);

getch();
return;
}

void call(void *ptr)
{
char ch;

printf(" Enter the data type(i=integer/f=float)?");
ch=tolower(getch());

if(ch== f )
{
printf(" Enter the value:");
scanf("%f",ptr);
}
else
{
printf(" Enter the value:");
scanf("%d",ptr);
}
}


In the above example a single function(name call) used for taking any type of data.
Here i only accept Float&Integer value.(But you can use any type of data by modifying the function)

But it has a problem i.e for taking any value I used a option e.g(for integer
you have to press i or f for float)as if i used %d in scanf then it only accept integer value or
if i used %f then it only accept only floating value.

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.114 seconds with 25 queries.