Thread: How about this one

  1. #1
    Registered User
    Join Date
    Mar 2012
    Location
    US
    Posts
    49

    How about this one

    int
    Code:
    #include <stdio.h>
    int f(int* a, int* b);
    int main() {
       int a = 6, b = 7, c = 8;
      b = f(&c, &a);
      printf("a = %d, b = %d, c = %d\n", a, b, c);    
      return 0;
    }
    
    int f(int* a, int* b) {
      *a = *a + *b;
       *b = *a - *b;
      printf("a = %d, b = %d\n", *a, *b);
      return 3*(*b);
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How about you read your previous thread again, and then post what YOU think is happening.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Location
    US
    Posts
    49
    I got everything working right I just dont know how c=14 if theres no equation or anything given for it?

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    But there is. c is not modified in main, it's modified in f(). Remember, the address of c is passed as the first parameter to f().

  5. #5
    Registered User
    Join Date
    Mar 2012
    Location
    US
    Posts
    49
    Ahhh gotcha. Thanks

Popular pages Recent additions subscribe to a feed