Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 18th, 2005, 12:46 PM   #1
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
silly little question...

Can someone do something like...

int main()
{
int something;
int something_else;
int elaborate_variable();
{
//silly variable code
}

something = 42;
something_else = 42;
//silly main code

return 0;
}

I don't know if you're seeing where I'm trying to get at, so I'll try to explain...

I've noticed that fucntion *main* is declared as being a variable (as using the int main()), so it could be (I suppose) possible to make dandy little variables that interact with other stuff, right? I don't know if it would be usefull in anyway, but by saying:
int something()
I'm declaring a variable which could (as far as I know) have some code embebed in it...

This is a real noob talking, so it will probably sound really stupid... but it was just a though.

Could anyone inlighten me?
__________________
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
Broax is offline   Reply With Quote
Old Jan 18th, 2005, 1:44 PM   #2
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
what you're talking about is called a function it work's something like this

int avalue;
int bvalue;
int main()
{
  avalue=3;
  a();
  bvalue=4;
  b();
}

void a(int value)
{
  printf("%d\n", value);
}

void b(int value)
{
  value = value * avalue;
  printf("%d\n", value);
}

that will print
3
12

good luck

Dizz
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 18th, 2005, 3:13 PM   #3
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
hmmm... I think I got the point (I think)...

but thanks.. anyway, here comes a real stupid question, and I know that this is stupid but I just don't understand this! I've read it over and over again, but I don't get it why are there decimal, octo and hexadecima integers... I mean... I understand what they are... (decimal go from 0 to 9, octo from 0 to 7, and hexadecimal from 0 to 9 plus A to F), but what I don't know is why do they exist?!

Why can't one just use decimal characters for even and ever? this is just too confusing, and made the whole learning process a lot harder (if you take into consideration that I flunked math).

This whole mathematical part is a bit confusing, including the floating point... I mean.. I understand that 6.0e2 is something like 10.0 x 10 to the power of 2 (I think this is how one says it in english), but I don't understand is where this comes in place on the programming world...

Maybe it's my I-hate-math-atitude... I dunno!

I also don't really understand the data type diferences, so maybe someone could explain 2 or 3 data types to me, and then I could figure the rest by myself (I suppose).

I just need to figure the pattern on these things...

Again, thanks for all the help so far!

EDIT: BTW, what's the diference beteween a variable and a constant? As far as I can tell they do the same job (except that a variable can't be changed by any program input), but it seems as though constants are a bit obsolete...
__________________
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA

Last edited by Broax; Jan 18th, 2005 at 3:22 PM.
Broax is offline   Reply With Quote
Old Jan 18th, 2005, 3:36 PM   #4
Osiris
Newbie
 
Join Date: Jan 2005
Posts: 2
Rep Power: 0 Osiris is on a distinguished road
Quote:
Originally Posted by Broax
hmmm... I think I got the point (I think)...

but thanks.. anyway, here comes a real stupid question, and I know that this is stupid but I just don't understand this! I've read it over and over again, but I don't get it why are there decimal, octo and hexadecima integers... I mean... I understand what they are... (decimal go from 0 to 9, octo from 0 to 7, and hexadecimal from 0 to 9 plus A to F), but what I don't know is why do they exist?!

Why can't one just use decimal characters for even and ever? this is just too confusing, and made the whole learning process a lot harder (if you take into consideration that I flunked math).
We could probably use it forever and ever, but it would be kind of impossible for computers since all they are capable of handling is on/off (1/0)...

hex makes binary easy to read... I don't know about octo, i've never really dealt that much with it and I don't know any sick person that would enjoy themselves with such number system.

Quote:
This whole mathematical part is a bit confusing, including the floating point... I mean.. I understand that 6.0e2 is something like 10.0 x 10 to the power of 2 (I think this is how one says it in english), but I don't understand is where this comes in place on the programming world...

Maybe it's my I-hate-math-atitude... I dunno!

floating point? isn't that just like an integer but it supports decimal values?

Quote:
I also don't really understand the data type diferences, so maybe someone could explain 2 or 3 data types to me, and then I could figure the rest by myself (I suppose).

I just need to figure the pattern on these things...
integer are whole numbers
char are really unsigned integers used to represent characters

Quote:
Again, thanks for all the help so far!

EDIT: BTW, what's the diference beteween a variable and a constant? As far as I can tell they do the same job (except that a variable can't be changed by any program input), but it seems as though constants are a bit obsolete...
yeah, i see what you mean... I really don't use constants myself, if I don't want to change the value of an integer I just make sure that that varible is not used for input... but, making a variable constant, just makes sure and lets you rest at ease that that variable won't be changed, because it is constant.
Osiris is offline   Reply With Quote
Old Jan 18th, 2005, 3:43 PM   #5
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
http://www.programmingforums.org/for...hread.php?t=83

For the functions and data types, that's really the best explanation I can give.

The computer is based on on/off switches, which can be represented by 1's and 0's, which is where we get binary. Octal and Hexadecimal are simpler ways of reading this.

For instance, let's take the number

10110010

Let the rightmost digit be digit 1, and the leftmost digit be digit 8. To represent that in hex, you take the lower 4 digits (digits 1-4), and the higher four digits and simply combine them. For instance, in this case, the right 4 digits equal 2 in hex, and the left four digits equal 0xB in hex. All you do to write them in Hex is combine them, so you get 0xB2 as the hexadecimal number. For octal, you take the 3 rightmost digits, than the next 3, and then the next (assuming digit 9 was 0) and simply combine those, so in this case it would be 262 in octal. As you can see, B2 in hex, or 262 in octal is a lot easier to read than 10110010.

A constant is a variable that doesn't change, and of course you can use the #define preprocessor directive. Don't worry, though, if you don't know about preprocessor directives yet. They're very easy to learn.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower

Last edited by Mjordan2nd; Jan 18th, 2005 at 3:56 PM.
Mjordan2nd is offline   Reply With Quote
Old Jan 18th, 2005, 4:13 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Usually, constants are used as replacements for numbers in the system. For example, if I use:
const maxDatabaseSize = 1000;
and use that in my code, I can change the database size simply by changing that one value, instead of hunting through 2000 lines for every instance of the value 1000 that I need to change.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jan 19th, 2005, 4:03 PM   #7
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
Talking

no, the funtion main is not a variable, the "keyword" "int" before the function is simply declaring the "return type" of the function. i get the impression that some of these replys are trying to over-complicate things. all the "int" does is say that "main" will "return" an integer. you can just as easily state "void" for the return type and disregard the "return = 0" statement. the other is done for form based on the "C" language (for purposes of error-checking...that "0" could also be a non-zero value which would indicate that something had gone wrong). sometimes you want functions to return a value to someone else and that is why functions have a return type. the C-style languages can get confusing this way. that is why JAVA and C# exist. fuck all that man, a lot of the questions you seem to ask could be answered better by a book. i don't know how the language barrier hurts that for you. i hope you do well.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Jan 19th, 2005, 4:14 PM   #8
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
uoooh.. that actually makes a lot of sense...

But programming books are expensive and I want to make sure before I invest any money that I can get interested enough so that I actually keep working on programming. Sometimes a lot that I want to do just doesn't stick, and I go try something else. So I don't want to give €35 for a book on c++ if after a month or something I decide that I'm not going anywere with it..

but thanks for the help..
__________________
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
Broax is offline   Reply With Quote
Old May 31st, 2006, 4:50 PM   #9
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Quote:
Originally Posted by bl00dninja
no, the funtion main is not a variable, the "keyword" "int" before the function is simply declaring the "return type" of the function. i get the impression that some of these replys are trying to over-complicate things. all the "int" does is say that "main" will "return" an integer. you can just as easily state "void" for the return type and disregard the "return = 0" statement. the other is done for form based on the "C" language (for purposes of error-checking...that "0" could also be a non-zero value which would indicate that something had gone wrong). sometimes you want functions to return a value to someone else and that is why functions have a return type. the C-style languages can get confusing this way. that is why JAVA and C# exist. fuck all that man, a lot of the questions you seem to ask could be answered better by a book. i don't know how the language barrier hurts that for you. i hope you do well.
That was the first post (on this forums) to contain the word "fuck" congrats. Bloodninja
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old May 31st, 2006, 5:13 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Nah, it wasn't the first post to contain that. Anyway, Blood is right about the int keyword. It's part of the pattern or prototype or declaration that tells the compiler how the function is supposed to be interfaced with. int myFunc (double x, char y); states that the function requires two arguments, one double and one char, and will return an int.

As for your other question, you need to develop a perception of the difference between an absolute value, binary in the case of the processor, such as fifteen. Now, "fifteen" is just a word, but we use it to express an absolute quantity. Count the fingers on both hands and the toes on one foot. Presuming you're equipped normally, that's the quantity we're talking about. Decimal, octal, hexadecimal, binary, are just numeric bases. We can express that quantity in all of them, with different symbols. Binary: 00001111 (8 bits, could be more), octal 017, decimal 15, hexadecimal 0f. As you can see, the larger the base, the fewer symbols are needed. Efficiency and ease of comprehension.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC