Taking it back to printf("Hello, world! \n");

Han sang yeob·2021년 1월 27일
0

Basic of C language

목록 보기
1/9

Algorithm

as put it simple, is step by step instructions.
For example, how to click ‘like’ in the video?

1. Move hand to mouse
2. grab the mouse
3. move the mouser till cusor hovers orver 1 video.
4. click left mouse button
5. move the mouse till cursor hovers over like button
6. click left mouse button

This is step for liking one video but how about 100 liking 100 videos?
Do we need to follow 6 steps over 100 times? How about if we shrink down to one statement?

So let’s assume that this entire function a likeVideo().

likeVideo(string vid){
1. Move hand to mouse
2. grab the mouse
3. move the mouser till cusor hovers orver 1 vid.
4. click left mouse button
5. move the mouse till cursor hovers over like button
6. click left mouse button
}

So basically, when I want someone to like the video, I m ‘calling’ this function.

Return

What if I want to tell the computer, “Hey you! I want you to tell me how many people liked this video!”

Well, this is a concept of ‘Return’. So to computer, we are telling ’I want you to return to me like count’. Every function can have return

likeVideo(string vid){
1. Move hand to mouse
2. grab the mouse
3. move the mouser till cusor hovers orver 1 vid.
4. click left mouse button
5. move the mouse till cursor hovers over like button
6. click left mouse button
Return … ;
}

or

#include <stdio.h>

int main(){
//main() -> entry of our program
//int -> data type of ‘0’
    printf("Hello world! \n"); 
    // \n -> new line char
    return 0;  -> so this ‘0’ signifies, everything is OK!
}

Function

Simply, another name for function is an algorithm.
Main() is called first when we run our program. In other words, identifier(the name of something). We can say like "so, the identifier of this function is main".

First, in that program, we want to print something, then return something. Both of them are example of ‘statements’. It is clear because both have ‘;’. We can think of statements as commend.The user is giving commend to program. for 0 in return 0;, means :),which the program run as we expected. We could use other value but I don’t see why we need to do that in here. We will talk about this furthermore. Int is called data type of 0. We are saying "Hey, we are going to return some integer" that is all it is saying.

For printf(“”);, this is function called from other places in somewhere in the program. Like,

Printf(){
//bla bla
}

So in printf("Hello world! \n");, we are just saying that ‘Hey, we want to use that code overthere inside of our program!’. But where is that code located? It comes from some library. And the library is placed in <stdio.h> (standardio). Inside of this library, one of the functions that is avaliable to use is printf(“”); function. I’m sure it is waaayyy more complicated then //bla bla but thinkfully, we don’t need to worry about that. So if we didn’t put #include<stdio.h>, the computer will say "bro, what is printf(“”);??" so this is the reason we need to include #include<stdio.h> before we call other functions.
Lastly, \n. this is called a ‘new line character’. Whenever, we are using the \n, it is saying that ’console, go to next line!’

profile
Learning IT in Vietnam

0개의 댓글