Jump to content

The Number War: Count to 100 or -100


RainDreamer

Recommended Posts

int add_1(n) {
	return n++;
}

int main(int argc, char *argv[]){
	printf("%d",add_1(90))
}

Compile and run

90

 

(If you haven't figured it out yet, i'm going to make the most complicated C program that just adds 1 to a number)

Edited by icantmakemodels
Link to comment
Share on other sites

#define @START_AT 91

int * n_plus_1_pointers(int * n){
	*n += 1;
	return n;
}

int main(int argc, char * argv){
	int n=@START_AT;
	printf("%d",n_plus_1_pointers(&n));
}

Compile and run

92

 

Edited by icantmakemodels
Link to comment
Share on other sites

#define @START_AT 93 

int n_plus_1_pointers_overcomplicated(int n){
	int * s = (int *)malloc(sizeof(int));
	*s = n++;
	return s;
}

int main(int argc, char *argv[]){
	int n = @START_AT;
	n = n_plus_1_pointers_overcomplicated(&n);
	printf("%d",n);
	free(&n);
}

Compile and run

94

 

Edited by icantmakemodels
Fixed a bug that caused a memory leak when incrementing a variable.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...