the line of code below giving error gcc
compiler when file saved check.c
. error @ line void swap_address(int& a, int& b)
as
error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
i have used command compile c file: gcc -o check check.c
but same code working fine if use g++
compiler using: g++ -o check check.c
please provide me reason why working g++
, not gcc
.
the code:
#include <stdio.h> void swap_value(int a, int b) { a=a+b; b=a-b; a=a-b; } void swap_address(int& a, int& b) { a=a+b; b=a-b; a=a-b; } int main() { int i=5,j=3; swap_value(i,j); printf("%d%d\n", i, j); swap_address(i,j); printf("%d%d\n", i, j); return 0; }
swap_address()
has reference parameters file has ".c" extension, gcc
assuming c file , producing error because reference parameters not part of c.
g++
taking file being c++, happy reference parameters.