Curious to know

Hi again!And happy new year to all.Just got to attained an interview and was asked about some c questions.I am not sure I am posting in right forum, but would like to know what does these lines means?Can anyone tell me?

int main()
int k=printf("Hello");
return 0;

That is C language.
It would compile into a very small program that outputs “Hello” (without the quotes).

The last line is NOT part of the program and would throw a compiler error. It appears to be a reference to the output (e.g. O/P)

All C programs require an “entry point” and the default is called main (which always returns a result code as an integer.
The routine is enclosed in curly braces. The statement ‘printf’ is a formatted print function that is part of [one of] the native libraries in C

Here is an overview reference about the language.

If you do a google search you can find it yourself…

You’re outputting “Hello” on the screen but since the function main has to return an integer (you said that when you named the function “int main()”) you return 0 (meaning that the function has succeed)

But if the function doesn’t work, the exit function will end it up and return a code error 10

I’m more than happy to help but sometimes I wish that people would use Google a bit. :wink:

Edit: Seems that ParkinT was quicker than me :slight_smile:

Ok I got it a little bit.Thanks for quick reply.Going line by line, int main() is a function which is integer.And if it returns error, it returns error code 10 and exits the function.Since the functions dosent work,it is returning 0.Im I right?

Almost there but…No :slight_smile:

If the function main works perfectly, it will print the message on screen and the value returned will be 0.

If there’s an error, the value returned will be 10.

I agree and would much rather see a question posed as, “I searched for the answer, found this, but would like a little more clarification from someone with direct experience in this area”
This is a very helpful community, but there is A LOT to be gained from [even an attempt at] seeking the answer on your own first.

Thanks a lot.and the link is very useful.

Thats very true.and I will keep it in mind next time :slight_smile: