Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing pointers to functions in C
#1
Pointers can be passed to functions to modify the original data.

void increment(int *num) {
    (*num)++;
}

int main() {
    int x = 5;
    increment(&x);
    printf("x: %d\n", x); // Output: 6
    return 0;
}
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Uninitialized pointers in C Qomplainerz 0 221 07-26-2023, 07:10 AM
Last Post: Qomplainerz
  Overview of standard C library functions Qomplainerz 0 224 07-25-2023, 01:28 PM
Last Post: Qomplainerz
  File pointers and streams in C Qomplainerz 0 227 07-25-2023, 01:24 PM
Last Post: Qomplainerz
  Understanding pointers and memory addresses in C Qomplainerz 0 248 07-25-2023, 11:41 AM
Last Post: Qomplainerz
  Declaring and defining functions in C Qomplainerz 0 293 07-25-2023, 11:01 AM
Last Post: Qomplainerz
  Input and Output functions (printf and scanf) in C Qomplainerz 0 244 07-25-2023, 10:52 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 2 Guest(s)