Dev C: invalid operand to binary & in scanf statement

This is a discussion on Dev C: invalid operand to binary & in scanf statement within the C++ Programming forums, part of the General Programming Boards category; Hi i am using Dev C/C++. I have used a very simple program #include<stdio.h> #include<conio.h> Code: int main() { int ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    1

    Dev C: invalid operand to binary & in scanf statement

    Hi i am using Dev C/C++.
    I have used a very simple program

    #include<stdio.h>
    #include<conio.h>

    Code:
    int main()
    {
        int  basic_salary , allowance , rent , gross;
         scanf( "%d " & basic_salary);
        allowance = 0.4*basic_salary;
        rent = 0.2*allowance;
        gross = basic_salary - allowance- rent;
        printf("The gross salary is %d",gross);
        getch();
       return 0 ;
    }
    I have stored this file in under .C extension..I receive error in scanf as
    invalid operands to binary &

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You are missing a comma.

    Take a look at the error line and think what is there that would make the compiler think that & is a binary operator in this context.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    1) This is the C++ forum, not the C forum.

    2) Dev-C++ is no longer under development. It's commonly recommended you switch IDE's (Code::Blocks or Visual Studio, etc).

    3) You're missing a comma before the & symbol. I'd recommend Googling the function next time:

    scanf - C++ Reference

    Shows the correct usage.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with C program
    By ChrisH in forum C Programming
    Replies: 38
    Last Post: 11-13-2004, 01:11 AM
  2. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  3. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM
  4. Flood of errors when include .h
    By erik2004 in forum C++ Programming
    Replies: 14
    Last Post: 12-07-2002, 07:37 AM
  5. misc.c:3210: invalid operands to binary +
    By Unregistered in forum Linux Programming
    Replies: 2
    Last Post: 07-19-2002, 08:00 AM

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