![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
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() 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 |
|
|
|
|
|
#2 |
|
Professional Programmer
|
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 |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
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. |
|
|
|
|
|
#4 | ||||
|
Newbie
Join Date: Jan 2005
Posts: 2
Rep Power: 0
![]() |
Quote:
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:
floating point? isn't that just like an integer but it supports decimal values? Quote:
char are really unsigned integers used to represent characters Quote:
|
||||
|
|
|
|
|
#5 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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. |
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Usually, constants are used as replacements for numbers in the system. For example, if I use:
const maxDatabaseSize = 1000; |
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#9 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Quote:
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
|
#10 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|