Why this code does not work correctly (gives random numbers from memory)?
#include <stdio.h> int fun(int n, ... ){ int *ptr = &n; ptr++; return *ptr; } int main() { printf("%d\n", fun(1, 10)); return 0; } Why this code does not work correctly (gives random numbers from memory)?
#include <stdio.h> int fun(int n, ... ){ int *ptr = &n; ptr++; return *ptr; } int main() { printf("%d\n", fun(1, 10)); return 0; } #include <stdarg.h> #include <stdio.h> int fun(int n, ...) { va_list args; va_start(args, n); int i = va_arg(args, int); va_end(args); return i; } int main() { printf("%d\n", fun(1, 10)); return 0; } Source: https://ru.stackoverflow.com/questions/941948/
All Articles