Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C Add Function


Scar0ptics's Avatar
Member
0 0

I created a file within a Linux OS and used Nano to create the file. I named this file "Add.c" and compiled it by using "g++". I know some people may prefer other text editors, and that's fine.

1.) Create an AddOne function so that it correctly adds one to the value of x and prints:

X: 0 X: 1

#include <stdio.h>

int main(int argc, char ** argv){ int x = 0; printf("X: %d \n", x);

// put solution here

printf("X: %d \n", x); }


Scar0ptics's Avatar
Member
0 0

void Addone (int *x) { *x = *x+1;

}

// I understand that there are other ways of doing this and I am open to all constructive criticism, but before you comment please consider that this code is written so the built-in Linux compiler (g++) can understand it.


_spartax_'s Avatar
Member
0 0

#include <stdio.h>

void inc(int*);

int main(int argc, char const* argv[]) { int foo = 0xDEAD; printf("%x\n", foo); inc(&foo); printf("%x\n", foo); return 0; }

void inc(int* x) { asm volatile("incl (%rdi)"); }


Scar0ptics's Avatar
Member
0 0

you got a smiley in your code man.