English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm currently learning C... And I don't have the idea why my instructor gave me this code...

#include
#include
main()
{
printf("Hello World");
getch();
}

Can someone help me with this? To explain how each line works and why there are brackets and semi-colons found withing the code...
Also...why in line 3, there is "main()".
And what is the use of "getch()" & "printf()"?

Please...I badly need your help...

2006-11-12 03:11:05 · 5 answers · asked by Anonymous in Computers & Internet Programming & Design

5 answers

I think you need to pick up a book and start studying. this is the most basic of programs, and if you cant understand this, then its time to decide on another career path. Im not trying to be mean or anything, just pointing out the reality.

2006-11-13 01:39:11 · answer #1 · answered by justme 7 · 0 0

Hey, are u new at programming? This is the simplest code the students learn in first page of C-programming book. Sorry, don't misunderstand me, actually I don't want to underestimate u... Anyways, I'm answering u one-by-one.

"stdio.h" (standard input-output) and "conio.h" (console input-output) are two header files. Header files are those files where built-in functions' prototypes are declared. As a beginner, u may 've some difficulties to understand some terms. (e.g.: Look, "printf()" is a built-in function whose prototype/meaning is declared in header-file "stdio.h" & "getch()" is another built-in function whose prototype/meaning is declared in header-file "conio.h".

Now, main() is the first user-written function run when a program starts. Ur main program-codes should be written within main() function.

Putting semi-colons at the end of each line is the rule. Note that, after main() u shouldn't put semi-colon. Okay?

"printf" is the function responsible for printing the line "Hello World" on console-screen.

"getch" --It's function is to wait for the user to press any key on the keyboard. When it does, it passes back the key that was pressed. However, in ur case u don't need to use this information - we are simply using this as a way of keeping the results displayed on the console while we look at it, and then indicating that we have finished looking by pressing a key.
- - - - - - - - - - - - - - - - -- - - - - -- - - - -- - - - -- - - - - -
Don't hesitate to mail me, if u find any difficulty. Bye.

2006-11-12 12:05:11 · answer #2 · answered by Innocence Redefined 5 · 0 0

/* stdio.h is a library file, where the definition of printf() and scanf() etc.. is written. #include is a preprocessor directive. */

#include

/*you are using a function getch() for which definition is already written in conio.h, so it is needed.*/

#include

/* main() is a function which is an entry point of all the C programs. */

main()

{ // this curly brace indicates the beginning of the program body

printf("Hello World"); // prints Hello World on the screen

/* use of getch() in this context is, until you hit a character the output will be visible. The functionality of getch() is, it takes a character as an input */
getch();
} // Closing of the function body.
-----------------------------------------------------------------------------
http://santoshsy.googlepages.com

2006-11-12 12:26:20 · answer #3 · answered by the_init 1 · 0 0

#include
dis line basically includes d "stdio.h" library into ur prog
stdio stands 4 standard input output
this library consists of standard functions for input n output data

#include
is a library wch is used 2 clear d screen(im not too sure abt dis one though)

main()=this is the main function
this is wher the program begins
when d compiler compiles d program it starts from d main function

then u hav " {"
this is just the syntax to show d start of a funtion(in this case main() )
and " }" is used 2 indicate end of d function.....

"printf()" as d name indicates is used to print d output on d screen
whatever u type in d brackets will b displayed on d screen
eg:printf(" hello"); will print "hello" on d screen

";" inidicates d end of line in C

getch()- stands for get character its a funtion of conio library
i really wont b able 2 tell u precisely wht dis function does

u can chk out www.cprogramming.com

2006-11-12 12:28:21 · answer #4 · answered by sak 2 · 0 0

Print means the result of the code is to print "Hello World" in a popup once the program is run.
Semicolons indicate the next line of code.
Bracket just indicates separating that section of code.

As for the rest, unsure, sorry I haven't done programming in a bit.

2006-11-12 11:19:13 · answer #5 · answered by Anonymous · 0 0

fedest.com, questions and answers