Thread: Amusing corner case...

  1. #1
    Registered User
    Join Date
    Sep 2020
    Posts
    425

    Amusing corner case...

    What number comes after 0xE? Let's find out!

    Code:
    #include <stdio.h>
    
    
    int main(int argc,char *argv[]) {
      printf("0x%X\n",0xE+1);
    }
    Opps!:

    Code:
    $ gcc -o a a.c -Wall -pedantic
    a.c: In function ‘main’:
    a.c:4:17: error: invalid suffix "+1" on integer constant
       printf("0x%X\n",0xE+1);
    Last edited by hamster_nz; 10-19-2020 at 09:00 PM.

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    That's because 'E' is used in floating point literals. The compiler thinks 0xE+1 is nnnE+1 as in 3.14e+1 literal. Try to use (0xE)+1 instead.
    Last edited by flp1969; 10-20-2020 at 06:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An on the other corner with red shorts...
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-16-2008, 10:16 PM
  2. Invisibility is just around the corner!
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 08-06-2006, 04:12 PM
  3. Amusing links
    By hermit in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 10-10-2002, 06:19 AM
  4. Amusing
    By Clyde in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 09-12-2002, 01:17 AM
  5. cout<< only in box in corner
    By CARBUNCLE in forum C++ Programming
    Replies: 2
    Last Post: 05-02-2002, 07:04 AM

Tags for this Thread