First Steps | C Programming | Kovolff
Potential IDEs (Integrated Development Enviornments): CodeBlocks: http://www.codeblocks.org/ Visual Studio Code: https://code.visualstudio.com/ Visual Studio Community: https://visualstudio.microsoft.com/ Every program you write in C must have at the very minimum the function main(). This is the heart or flow controller of the whole program. That does not mean that your whole program must be coded within main(), but main() controls what gets called and when. Every function in C, including main(), gets created along the same lines. i.e. int main(void) { // Function Code printf(“hi guys”); return some_value; } Ahead of the function name (int in the sample above) you must define the return type of the function. After the function name within parentheses, you need to insert the parameters that act as inputs to the function. In the sample above the word void means that the function does not take or need any inputs for it to work. // Function Code is a comment and extends for only one line. Any line preceded by // is a comment. This type of comment is taken from C++, but can be used in C. The older way of commenting in C is: /* Function Code */ This type of comment can extend multiple lines, as long as it begins with /* and ends with */. Comments are useful to document certain sections of the program so that you or others can understand what is happening at this section. The comment Function Code denotes the section where the function does what it is supposed to do. This can go from one line to an infinite number of lines. Nevertheless it is advisable to limit your functions to carry out one task, instead of a whole plethora of jobs. Our function above does just one thing. It calls another function called printf(), which prints whatever is passed to it. In this case the string “hi guys”. printf() is one of C pre-built functions, but is stored in an external library called stdio (standard input output). To be able to call or use printf() we need to include this external library into our code, by inputting the code below at the start of our program. #include stdio.h Every time you run a c program an .exe (for Windows) or executable file gets created, when run reflects the functionality you programmed. Some notable escape combinations: \n: new line ie printf(“hi guys\nhow are you”); This prints: hi guys how are you \t: tab \a: makes a sound #C #newbie #programming
Download
1 formatsVideo Formats
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.