Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function pointers in C

Why does the following print 1. I was expecting it to print the address of the function pointer.

#include <stdio.h>

int main(main) {
  printf("%i",main);
  return 0;
}
like image 450
shreyasva Avatar asked Dec 04 '22 07:12

shreyasva


1 Answers

Pointers must be printed with %p. Anyway here there's an "aliasing" problem, rather odd but that's it: main gets the value of the first argument to function main that is, what usually is called "argc". if you call it with more arguments, you should see bigger number.

like image 162
ShinTakezou Avatar answered Dec 20 '22 13:12

ShinTakezou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!