Thread: What is the mistake in following code?

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    What is the mistake in following code?

    Dear all,
    I am unable to rectify the error in following code:-

    Code:
    void Add_int(int, int);
    int main(int argc, char* argv[])
    {
    	int (*function)( int, int);
      int x, y;
      float a,b;
      printf("Enter two int values\n");
      scanf("%d %d", &a, &b);
      function=Add_int; 
    	return 0;
    }
    
    void Add_int(int x, int y)
    {
      int sum=0;
      printf("%d",sum);
    }
    Regards,
    Swetha

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    for floats use scanf("%f"..., instead of %d

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    also your function pointer has a different type from the function (return type of th efunction differs)

    and posting your compilation wanrings will help to receive answers
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. where is my mistake following this code..
    By transgalactic2 in forum C Programming
    Replies: 9
    Last Post: 10-18-2008, 01:44 PM
  2. where is my mistake in undersanding the order of this code..
    By transgalactic2 in forum C Programming
    Replies: 9
    Last Post: 10-08-2008, 08:26 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM