I'm currently learning C... And I don't have the idea why my instructor gave me this code...
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
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()" %26amp; "printf()"?
Please...I badly need your help...
What does these lines in C mean?
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.
Reply: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.
Reply:/* stdio.h is a library file, where the definition of printf() and scanf() etc.. is written. #include is a preprocessor directive. */
#include %26lt;stdio.h%26gt;
/*you are using a function getch() for which definition is already written in conio.h, so it is needed.*/
#include %26lt;conio.h%26gt;
/* 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
Reply:#include%26lt;stdio.h%26gt;
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%26lt;conio.h%26gt;
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
Reply: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" %26amp; "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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment