Is this correct

This is a discussion on Is this correct within the C Programming forums, part of the General Programming Boards category; #include <stdio.h> int main() { int c=10, d=20; void swap(int *c, int *d); void change(int *c, int *d); printf("Before swap ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    7

    Is this correct

    #include <stdio.h>
    int main()
    {
    int c=10, d=20;
    void swap(int *c, int *d);
    void change(int *c, int *d);

    printf("Before swap c=%d , d=%d ,", c,d);
    swap(&c,&d);
    printf("After swap c=%d , d=%d ,", c,d);
    }

    void swap(int *c, int *d)
    {
    change(&c,d);
    }

    void change(int *c, int *d)
    {
    int t;
    t=**c;
    **c=*d;
    *d=t;
    }

    I am getting a compilation error

    kan1usp4.c:19: warning: type mismatch with previous implicit declaration
    kan1usp4.c:15: warning: previous implicit declaration of `change'
    kan1usp4.c:19: warning: `change' was previously implicitly declared to return `
    nt'
    kan1usp4.c: In function `change':
    kan1usp4.c:21: invalid type argument of `unary *'
    kan1usp4.c:22: invalid type argument of `unary *'

    On the face of it the program looks fine. But, then why is the compilation error.

    Thanks..Jack.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    7
    U r correct. Thanks for ur reply.

    Thanks..Jack

  3. #3
    0x01
    Join Date
    Sep 2001
    Posts
    88

    hmm.... Just try this.

    Code:
    #include "stdio.h"
    
    void swap(int *a, int *b)
    {
    	int temp;
    
    	// swap the values
    	temp = *a;
    	*a =   *b;
    	*b = temp;
    }
    
    int main()
    {
    	int x = 5, k = 10, temp;
    
    	printf("\n Before swap() : 'x' = %d , and 'k' = %d", x, k);
    	swap(&x, &k); // Swap the values of variables 'x', and 'k'
    	printf("\n After  swap() : 'x' = %d, and 'k' = %d", x, k);
    
    	return 0;
    }
    Try not to use something like -> int **c, just use one * ( *c) ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux for GNU/Linux is not correct?
    By password636 in forum Linux Programming
    Replies: 8
    Last Post: 03-31-2009, 08:30 PM
  2. Is this correct : passing strings?
    By socket in forum C Programming
    Replies: 15
    Last Post: 11-25-2008, 01:03 PM
  3. correct order to insert new node?
    By campermama in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2004, 07:51 PM
  4. Replies: 1
    Last Post: 05-26-2004, 12:58 AM
  5. Loop until enter correct value
    By jchanwh in forum C Programming
    Replies: 2
    Last Post: 11-27-2001, 12:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21