Jump to content

Need help with some basic terms

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
TheFirst

TheFirst

    Newbie

  • Members
  • Pip
  • 5 posts
Ok, so pretty much ive been trying to teach myself c and objective-c. All ive ever been taught was one semester in high school of c++, all of which was pretty basic stuff.

Now, my problem in teaching myself is that a lot of basic terms are never really defined. Kind of like when you first got the internet however long ago that was, and you didnt know what lmfao and rofl meant.. heh. I know Im gonna sound like an idiot by not knowing these things, but its only because im self-teaching myself and some things just arent clear to me.

Ok now on to embarassing myself..

Can anyone explain return values to me? Like at the end of an object you have return 0; I know return means that you are done with the current object and to return to the point after the object was called.. i think. But what about the 0? what does that tell it? And if it wa something besides 0, what would that mean?

If someone could help me out here, itd be much appreciated, and as I continue teaching myself Im sure ill find some more that I need help with. But ya, all the terms are really my weak point. Im very good at coding once I really get the terms down, Im a really fast learner, but FINDING the meaning of these words is just hard sometimes. Its almost like in every tutorial, you are expected to already know a different language, as if there is really no starting point to coding >.<


Awww man, myhead hurts. Ive gotten like no sleep all week due to this lol.

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
It sounds like you haven't gotten much use out of writing your own functions. Return statements do end the current function and return execution to the previous location, but they are also able to send that previous location a value. Consider the following example:
int return_a_value(void)
{
    return 5;
}

int main(void)
{
    printf("%d\n", return_a_value());
    return 0;
}
The "return 5" from the return_a_value function will give the value of 5 to printf, which will then subsequently write that value to the command terminal. When you tell main() to "return 0", it's basically doing the same, except it's giving that value to the operations that called main() in the first place, and that will subsequently go to the operating system and tell the OS whether or not your program ran successfully. If you "return 1" or some other value instead, you tell the OS that your program has exited abnormally. This doesn't sound like it would do much, but a common way for scripts to check if the programs they run have run successfully is to check their return values.

TheFirst said:

Its almost like in every tutorial, you are expected to already know a different language, as if there is really no starting point to coding >.<
I disagree. There are a few tutorials that break down the Hello World example program line-by-line and explain exactly what's going on. Also, when you're learning to program, you have to accept that you will encounter things that simply haven't been explained to any great detail, like how standard functions work or that char a = 'A' will be interpreted into a numerical value by the compiler behind the scenes. You can in every way still treat it just like it were a capitalized A, but you can also treat it as a number. These things aren't quite immediately explained because they open up a greater amount of complexity that new programmers aren't really ready to understand yet (such as writing multi-file programs, thus "#include" isn't fully explained).

We all went through this same learning process, and there will be things that elude you for a while, but don't be afraid to ask questions, and most importantly don't be afraid to experiment. There's plenty out there to learn, and coding can be quite rewarding.
Wow I changed my sig!

#3
Walle

Walle

    Learning Programmer

  • Members
  • PipPipPip
  • 75 posts
I'm also self teaching, although I started somewhat 10 years ago, and then had a looong break from it :) I recognize your problem exactly!

The return value is one way for a function to pass a value back to from where it was called.

Say you want to do the following:

int a;

a = yourfuncion();

Then you need "yourfunction()" to return the value that is to be assigned to a. This is done by the return statement. An example:

int addition(int va, int vb)
{
     return a+b;
}

int main()
{

int a = 1;
int b = 2;
int c = addition(a, b);

0 (zero) is often returned in order to tell that the function executed ok. You can then use the function in an if-statement, for example, to check if 0 was returned.

You can see what type is returned in the declaration of the function (important when using library functions). If the function is named "int function()" then the return type is int(eger). If the name is "float function()"..and so on :)
________________________________________________
"I'm not young enough to know everything." - Oscar Wilde

#4
TheFirst

TheFirst

    Newbie

  • Members
  • Pip
  • 5 posts
Thank you guys so much. Its like your explanations opened up a window back into my highschool class so long ago. That was exactly how I needed that explained. Its been years since I did any of this stuff So I had a general idea of different parts of coding, but I couldnt put all the parts back together right in my head.

Summary: you guys rock

#5
TheFirst

TheFirst

    Newbie

  • Members
  • Pip
  • 5 posts
Ok, so i ran into something new now that I have a question about. Im looking at an objective-c tutorial and was just wondering, when you create a class, you do that at the top of your program, is the @implementation how you would use it? Are these separate files? what im looking at makes it seem like they are since one is fraction.h and one is fraction.m. What is the difference between .h and .m?
Im realizing how far I have to go until i really know what im doing.

Whats making this difficult for me is that I had c++ in highschool and now im trying to learn objective-c and the names of things are different. Or maybe Im just too burned out tonight from 66 hour work weeks xD

The factory I work at has some huge government order of wire harnesses, so we can work however much ot we want through april, so im taking advantage of it. Gotta buy a new laptop since mine got stolen when I was in boot camp...

EDIT: And btw, I used to use bloodshed for c++. What the heck do I use for obj-c? I cant seem to find any answers..

Edited by TheFirst, 17 January 2010 - 12:52 AM.
another question