LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   C program: i am getting errors when compiling this simple program (http://www.linuxquestions.org/questions/programming-9/c-program-i-am-getting-errors-when-compiling-this-simple-program-4175440938/)

batman4 12-11-2012 06:02 AM

C program: i am getting errors when compiling this simple program
 
Code:


main(){
int x=12;
printf("%d%x\n",ox2,x);
}

getting errors
undefined ox2

Please help

manoj7410 12-11-2012 06:32 AM

Hi, u r using ox2 that is an invalid thing if u don't declare it. if u want to see hex values than simply %x is sufficient. and use it like this,

printf("%d %x", x,x);

batman4 12-11-2012 07:07 AM

Quote:

Originally Posted by manoj7410 (Post 4846870)
Hi, u r using ox2 that is an invalid thing if u don't declare it. if u want to see hex values than simply %x is sufficient. and use it like this,

printf("%d %x", x,x);



how should i declare it ....

batman4 12-11-2012 07:08 AM

Quote:

Originally Posted by batman4 (Post 4846899)
how should i declare it ....

if i want to see the integer value of it..

millgates 12-11-2012 07:12 AM

Quote:

Originally Posted by batman4 (Post 4846900)
if i want to see the integer value of it..

Integer value of what?
Didn't you mean "0x2" instead of "ox2"?

batman4 12-11-2012 07:35 AM

Quote:

Originally Posted by millgates (Post 4846903)
Integer value of what?
Didn't you mean "0x2" instead of "ox2"?

yes

batman4 12-11-2012 07:38 AM

Quote:

Originally Posted by batman4 (Post 4846900)
if i want to see the integer value of it..

what is ox2 in c language.. i am not getting this clear

millgates 12-11-2012 07:49 AM

0x2 is the number 2 in hex.
ox2 is nothing. It might be a variable if you declared it.

theNbomr 12-11-2012 09:23 AM

The tokens 'ox2' and '0x2' are interpreted by the compiler in completely distinct ways. The compiler sees any token beginning with the characters '0x' to be an integer constant value expressed in hexadecimal notation. Variables must have alpha characters as the first character in their name, and the token 'ox2' is interpreted as a variable name, just like the token 'x' that you have already used. Since that variable has not been declared, the compiler doesn't know about the type of the variable, and makes the accordant complaint.

--- rod.


All times are GMT -5. The time now is 05:39 AM.