Below is my code: When I run it, I get the following statements:
X is equal to 1 and k is equal to 1
X is equal to 0 and k is equal to 0
What I wish to achieve is to have both statements stating the same thing (equal to 1). I understand I can just set the integers x, and k respectively to 1 underneath the if statement, however I want to know how to store a value after the function is executed, so that x and k remain equal to one after execution of the second function.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void run_times( int runs);
int main (){
int i;
while ( i <3) {
run_times(i);
printf("Looped\n");
i++;
}
}
void run_times( int runs) {
int *x,k;
if (runs == 0) {
x = &k;
*x = 1;
printf("X is equal to %d and k is equal to%d\n", *x, k);
}
if (runs == 1){
printf("X is equal to %d and k is equal to%d\n", *x, k);
}
Thanks in advance