[C] How to allocate memory with C

#include<stdio.h>
#include<stdlib.h>
 
int function1(int, int);
int a;
 
int main(int argc, char *argv[]) {
 
    int b = 1, c = 2; 
    int *sum = NULL;
 
    sum = (int*)malloc(sizeof(int));
 
    *sum = function1(b, c);
    printf("%d\n", *sum);
 
    free(sum);
    system("read -n 1 -s -p \"Press any key to continue...\"");
 
    return 0;
}
 
int function1(int num1, int num2) {
    int s;
    s = num1 + num2;
    return s;
}



Comments

Popular posts from this blog

[OpenCV] What is gocv?

[OpenCV] Chapter01-05 Working with UI elements such as scrollbars in OpenCV window

[OpenCV] How to set up gocv