LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-14-2003, 03:29 PM   #1
linuxanswer
Member
 
Registered: Oct 2003
Distribution: woodY 3.0 stable
Posts: 61

Rep: Reputation: 15
operators


#include <stdio.h>

int main() {

int set;
int can = 4;

int += can;
printf("d", set);

return 0;

}

why this code give me output 268336224?
 
Old 12-14-2003, 03:30 PM   #2
linuxanswer
Member
 
Registered: Oct 2003
Distribution: woodY 3.0 stable
Posts: 61

Original Poster
Rep: Reputation: 15
sorry
int += can; NO

this 's the correct

set += can;


 
Old 12-14-2003, 03:31 PM   #3
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Because the variable 'set' is not initialized; it's just using whatever value was left-over in memory.

Also, if you are wanting to print out the value of set, the printf statement should use '%d' instead of 'd'.

Last edited by wapcaplet; 12-14-2003 at 03:32 PM.
 
Old 12-14-2003, 06:09 PM   #4
Tesl
Member
 
Registered: Jun 2003
Location: Durham, UK
Distribution: Slackware 9, Mandrake 9.1
Posts: 163

Rep: Reputation: 30
you need to initalize 'set' first

Code:
#include <stdio.h>

int main() {

int set = 0;
int can = 4;

int += can;
printf("d", set);

return 0;

}
If you dont initialise variables first, they will just contain garbage values
 
  


Reply


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
Operators *^ and >> GodSendDeath Programming 4 11-01-2004 09:47 PM
about bitwise operators? eshwar_ind Programming 17 10-25-2004 02:13 AM
C++, comparison operators, segfault exodist Programming 1 04-24-2004 03:03 PM
Bitwise operators kamransoomro84 Programming 8 04-22-2004 10:46 PM
arithmetic operators in Kylix3 (C++) herbie_52 Programming 2 05-23-2003 07:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:01 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration