please help me..
am using turbo c 3.00
i'm gettin a compile time error : Lvalue required.

-------------------------------------------------------------

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int func(int x,int y)
{
	int *ptr1=&x,*ptr2=&y;
	int **ptr_1,**ptr_2;

	*ptr_1=ptr1;
	*ptr_2=ptr2;
	printf("\nUsing function pointer : ");
	printf("\nx=%d\ny=%d",**ptr_1,**ptr_2);
	int sum=*ptr1+*ptr2;
	return sum;
}
main()
{
	int *fnptr(int,int); // declare a function pointer

	clrscr();
	fnptr=&func; //assigning address to fnptr- i get the error here
	printf("\nThe sum is %d",fnptr(10,20));
	getch();
}

Recommended Answers

All 2 Replies

> am using turbo c 3.00
Why?
It's 20+ years out of date, and my guess is you're running XP or something as your main OS.

Congratulations, you've turned your Ferrari into a horse and cart.

Get code::blocks or visual studio express (details in a search engine near you).

Oh, and re-read ALL the forum rules until you figure out how to use code tags. It's only mentioned half a dozen times, how did you manage to miss all of them.

commented: aha. Borland 3.0: preferred compiler of Amish Colonies everywhere. +8

>>i'm gettin a compile time error : Lvalue required.
which line?

>>*ptr_1=ptr1;
Probably cause an immediate crash. Why? Where does ptr_1 point to? It's undefined because it was never set to point anywhere. You can't just use a double star pointer like you are trying to do -- they don't work like that.

Here is a simple example

int main()
{
    int x;
    int* p = &x;
    int**p1 = &p;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.