U
U
unclechu2014-08-12 00:44:59
C++ / C#
unclechu, 2014-08-12 00:44:59

How to pass a reference to a variable to a function in C (without pluses)?

There is a code example in C++:

void square(int x, int& result) {
    result = x * x;
}

What will be the analogue for Sei without pluses?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
unclechu, 2014-08-13
@unclechu

#include <stdio.h>

void square(int x, int *result) {
    *result = x * x;
}

int main() {
    int a = 5;
    printf("before: %d\n", a); // 5
    square(10, &a);
    printf("after: %d\n", a); // 100
    return 0;
}

S
Sergey, 2014-08-12
Protko @Fesor

void square(int x, int *result) {
    *result = x * x;
}

int main() {
    int r;
    square(10, &r);

    return 0;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question