C or C++ code

This is a discussion on C or C++ code within the C Programming forums, part of the General Programming Boards category; I posted this code on another forum and was blasted because it is supposedly not C, but C++. Can someone ...

  1. #1
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    C or C++ code

    I posted this code on another forum and was blasted because it is supposedly not C, but C++. Can someone please show me wherein this code is not legitimate C code? I dont' see it.

    Code:
    #include <stdio.h>
     
    int main(unsigned char *argv[], int argc)
    {
      //declare two integers and load them with unique values
      int x = 5;
      int y = 3;
      
      //report the pre-algorithm values to the user
      printf("before:\n");
      printf("x = %d\n", x);  
      printf("y = %d\n", y);
      
      //the 1st variable now holds the sum of both integers (x = 5 + 3 or x = 8)
      x = x + y;
    
      //the 2nd variable now holds the result of subtracting its original value from the sum
      //(y = 8 - 3 or y = 5)
      y = x - y;
      
       //the 1st variable now holds the result of subtracting its 2nd variable from the sum 
      //(x = 8 - 5 or x = 3) 
      x = x - y; 
    
     
     //report the post-algorithm values to the user
      printf("after:\n");  
      printf("x = %d\n", x);  
      printf("y = %d\n", y);
    
    }
    Thanks in advance.

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    It's C99, except the parameters of main are the wrong way around. It should be one of:
    Code:
    int main(int argc, char *argv[])
    int main(void)
    It would be valid C89 (more common) if:

    (a) you removed the C99/C++ style // comments, or replaced them with /* */ comments.
    (b) you added an explicit return 0; on the end of the main function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 09:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21