this question has answer here:
i have 2 questions here.
q1: following program output(on 32-bit little-endian machine):
int main() { long long = 0x1, b = 0x2, c = 0x3; printf("a = %d, b = %d, c = %d.\n", a, b, c); return 0; }
and why?
q2:
why output of a
, b
, c
different?
void func(int a, int b, int c) { printf("a = %d, b = %d, c = %d.\n", a, b, c); } int main() { long long = 0x1, b = 0x2, c = 0x3; printf("a = %d, b = %d, c = %d.\n", a, b, c); func(a, b, c); return 0; }
for q1: thumb rule default pramaeters should on right handside, func(int = 1, int b, int c)
voilates rule because of =1. show error because if write func(5,6) compiler not understand 5 assigned a
or b
. while calling functions parameters assigned left right directions. basic funda.
simlarily func(int = 1, int b, int c = 3)
if call func(7), compiler try assign 7
a
, there nothing b
. cause , error.
Comments
Post a Comment