Thread: very simple doubt

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    3

    very simple doubt

    Hello all, i'm trying to get the result of an expression using the exponential (^) but it returns wrong values:

    printf("%d\n", 3^0);
    printf("%d\n", 3^1);
    printf("%d\n", 3^2);

    output:

    3
    2
    1

    Do you know what i'm doing wrong? I'm using gcc compiler.
    Thanks.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    The ^ is the exclusive or operator in C, not exponential notation.

    Jim

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    That's not exponential, it's a bitwise xor operator. For exponential, include <math.h> and use pow().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple game server doubt
    By Tesctassa in forum Linux Programming
    Replies: 4
    Last Post: 09-09-2009, 08:53 AM
  2. A simple doubt which striked me while reading OS
    By chottachatri in forum C Programming
    Replies: 3
    Last Post: 10-30-2008, 07:14 PM
  3. A very simple doubt
    By afser in forum C Programming
    Replies: 7
    Last Post: 10-26-2008, 02:30 PM
  4. a simple doubt!
    By chottachatri in forum C Programming
    Replies: 7
    Last Post: 10-10-2008, 01:42 PM
  5. a simple doubt in graphics
    By nikhil_trichy in forum Game Programming
    Replies: 7
    Last Post: 02-02-2006, 10:01 PM