Like Tree3Likes
  • 2 Post By Salem
  • 1 Post By anduril462

How about this one

This is a discussion on How about this one within the C Programming forums, part of the General Programming Boards category; int Code: #include <stdio.h> int f(int* a, int* b); int main() { int a = 6, b = 7, c ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    How about you read your previous thread again, and then post what YOU think is happening.
    anduril462 and Bsmooth01 like this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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,516
    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().
    Bsmooth01 likes this.

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

Popular pages Recent additions subscribe to a feed

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