LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-11-2012, 05:02 AM   #1
batman4
Member
 
Registered: Jul 2012
Posts: 47

Rep: Reputation: Disabled
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
 
Old 12-11-2012, 05:32 AM   #2
manoj7410
Member
 
Registered: Jun 2012
Location: India
Distribution: 2.6.x
Posts: 40

Rep: Reputation: Disabled
Wink

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);
 
1 members found this post helpful.
Old 12-11-2012, 06:07 AM   #3
batman4
Member
 
Registered: Jul 2012
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by manoj7410 View Post
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 ....
 
Old 12-11-2012, 06:08 AM   #4
batman4
Member
 
Registered: Jul 2012
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by batman4 View Post
how should i declare it ....
if i want to see the integer value of it..
 
Old 12-11-2012, 06:12 AM   #5
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 651

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by batman4 View Post
if i want to see the integer value of it..
Integer value of what?
Didn't you mean "0x2" instead of "ox2"?
 
Old 12-11-2012, 06:35 AM   #6
batman4
Member
 
Registered: Jul 2012
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by millgates View Post
Integer value of what?
Didn't you mean "0x2" instead of "ox2"?
yes
 
Old 12-11-2012, 06:38 AM   #7
batman4
Member
 
Registered: Jul 2012
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by batman4 View Post
if i want to see the integer value of it..
what is ox2 in c language.. i am not getting this clear
 
Old 12-11-2012, 06:49 AM   #8
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 651

Rep: Reputation: 269Reputation: 269Reputation: 269
0x2 is the number 2 in hex.
ox2 is nothing. It might be a variable if you declared it.
 
Old 12-11-2012, 08:23 AM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
  


Reply

Tags
programing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program compiling errors baronobeefdip Linux - Software 4 10-09-2012 05:00 PM
Compiling simple c program? meniscus Linux - Newbie 3 01-15-2007 04:51 AM
compiling a simple program with qt fakie_flip Linux - Software 1 01-18-2006 01:33 AM
my first C++ program, errors while compiling lu543285 Programming 11 09-26-2004 03:42 AM
Compiling a simple C++ program kbeaver Programming 27 02-06-2004 08:02 PM


All times are GMT -5. The time now is 01:07 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration