I know that my questions are very simple but googleing them didn't get me any useful results... They'r probably too simple!!
No. 1
char* createStr(){
char* str1 = malloc(10 * sizeof(char));
printf("str1 address in memory : %p\n", &str1);
return str1;
}
int main(void){
char* str2 = createStr();
printf("str2 address in memory : %p\n", &str2);
}
Result:
str1 address in memory : 0x7fffed611fc8
str2 address in memory : 0x7fffed611fe8
Why are the addresses different in and out of the createStr() function and how can I free(str1)???
No. 2
int main(int argc, int *argv[]){
printf("Basename is %s ", (char*) argv[0]);
if(argc > 1 ){
printf("and integer arg is : %d.\n", (int) *argv[1]);
}
}
If I compile and run $ ./test 3
, how can I get int 3?
Result:
Basename is ./test and integer arg is : 1380909107.