The thing with both C and Python is that you can actually change the variable type by using a function. An example of this is atoi()
which converts a char * (string)
into an int
. So I experimented it by making a function:
#include <stdio.h>
#include <stdlib.h>
int make_int(char *str);
int main() {
char str[256];
scanf("%255s", str);
printf("%i\n", make_int(str));
}
int make_int(char *str) {
return atoi(str);
}
It works as intended, but what I did not account for is that in C, you have to tell the variable what kind it is, unlike Python, where you can just make a name and assign it. I want to actually do other variables, but it might get more complicated in the process.
Q: How do I make a function where the parameters are actually random kinds like how Python does it? How do I actually change any variable to an int
as well?