A small difference between C and Java

Source: Internet
Author: User

C LanguageFunction Overloading is not supported. If two identical functions are defined, an error is returned.

Eg:

// Test. c

# Include <stdio. h>
# Include <stdlib. h>

Int add (int A, int B)
{
Return A + B;
}

Int add (int A, int B, int C)
{
Return A + B + C;
}

Int main (INT argc, char * argv [])
{
If (argc! = 3 & argc! = 4)
{
Printf ("usage ./ProgramName: int Int or./program name: int/N ");
Exit (1 );
}

If (argc = 3 ){
Printf ("% S + % s = % d/N", argv [1], argv [2], add (atoi (argv [1]), atoi (argv [2]);
} Else {
Printf ("% S + % s = % d/N", argv [1], argv [2], argv [3], add (atoi (argv [1]), atoi (argv [2]), atoi (argv [3]);
}
Return 0;
}

 

Compilation, error:

Test. C: 9: Error: conflict with the 'add' type
Test. C: 5: Error: 'add' is defined in this
Test. C: In the 'main' function:
Test. C: 23: Error: Too few arguments are provided to the 'add' function.

 

After the name is changed, it runs normally:

Alei @ Alei-desktop :~ $ GCC test. C-o Test
Alei @ Alei-desktop :~ $./Test
Usage./program name int Int or./program name int
Alei @ Alei-desktop :~ $./Test 12 13
12 + 13 = 25
Alei @ Alei-desktop :~ $./Test 12 13 14
12 + 13 + 14 = 39

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.