To change the value of x
from within a function, have try()
take a pointer to the variable and change it there.
e.g.,
void try(int *x)
{
*x = 11;
}
int main()
{
int x = 10;
try(&x);
printf("%d",x);
return 0;
}
More Related Contents:
- Explanation of output of this C code
- How does this foo function works?
- code ran into segmentation fault error.how to fix? [closed]
- Splitting a string into words
- Can x86’s MOV really be “free”? Why can’t I reproduce this at all?
- Can I share a file descriptor to another process on linux or are they local to the process?
- Concept of void pointer in C programming
- Assign one struct to another in C
- How to declare strings in C [duplicate]
- What happens to a float variable when %d is used in a printf?
- What is the function of “(void) (&_min1 == &_min2)” in the min macro in kernel.h?
- How to prevent system hang before watchdog timer task kicks in
- Why does integer division by zero result in a floating point exception?
- Algorithm to rotate an image 90 degrees in place? (No extra memory)
- How do I run a C program from VIM?
- What are the implications of the linux __user macro?
- warning: left shift count >= width of type
- Get scanf to quit when it reads a newline?
- Can I omit return from main in C? [duplicate]
- state machines tutorials [closed]
- How to include a dynamic array INSIDE a struct in C?
- Why do you have to link the math library in C?
- Open directory using C
- AES (aes-cbc-128, aes-cbc-192, aes-cbc-256) encryption/decryption with openssl C
- Use a dope vector to access arbitrary axial slices of a multidimensional array?
- Exceeding array bound in C — Why does this NOT crash?
- C initialize array within structure
- JSON requests in C using libcurl
- How to store a variable at a specific memory location?
- What is the difference between %f and %lf in C?