[ EN | PT ] “Hello World” in C explained | “Olá Mundo” em C explicado

in programming •  2 years ago 

Banner

English Version

Commonly, the first program written in a programming language is a “Hello World”, or “Hello World. Time to learn to use some C language to program. Start by opening your notepad, or any other plain text editor, and save this in a file named Hello.c:

#include <stdio.h>
/* This program will write "Hello world" to the console */
int main()
{
    printf("Hello world!\n");
    return 0;
}

The text of a C program is also known as the program code, or. simply, source code. This code is the program written in a programming language, such as Rust, PHP, Java or any other of them (in our case, the C language).

Shall we now analyze this code a little more specifically?

Line 1 represents the import of a library that will be used in the program (in our case, the stdio library, or “standard input and output”). This library will be responsible for writing things to the screen or capturing user-submitted data.

Line 2 is a comment, a code snippet that will not be used by the compiler, it could be documentation, name of the program author, description of functionality or anything else.

Line 3 represents the initialization of the main function, or main function. Everything inside it will run when the computer runs that program. The contents of this function are enclosed in braces { and }, on lines 4 and 7. The keyword int says that this function will return an integer (just like a math function), and the value 0 is used ( zero) as the default return value for the main function whenever there are no errors.

Line 5 calls the printf function, which will write its content to the console, in this case our “Hello, World”.

Line 6 indicates the function return. As we had no errors in the execution, we will return 0 (zero).

Compiling the program on Linux is quite simple. Open the folder where you have saved your file, and use the following command:

$ gcc Hello.c -o Hello

And to run it, just use the following command:

$ ./Hello

And that's it, the message Hello, world! will appear on your screen.

Did you like the tutorial? Was there any doubt? Do you have any add-ons? Leave it in the comments 😄🥰



odysee



Versão em Português

Comumente, o primeiro programa escrito em uma linguagem de programação é um “Hello World”, ou “Olá Mundo. Hora de aprender a usar um pouco da linguagem C para programar. Comece abrindo seu bloco de notas, ou qualquer outro editor de texto simples, e salve isso em um arquivo com o nome Hello.c:

#include <stdio.h>
/* Este programa vai escrever "Olá mundo" no console */
int main()
{
    printf("Olá, mundo!\n");
    return 0;
}

O texto de um programa em C também é conhecido como o código de programa, ou. simplesmente, código fonte. Esse código é o programa escrito em uma linguagem de programação, como Rust, PHP, Java ou qualquer outra delas (no nosso caso, a linguagem C).

Vamos analisar agora esse código de uma forma um pouco mais específica?

A linha 1 representa a importação de uma biblioteca que será usa no programa (no nosso caso, a biblioteca stdio, ou “standard input and output”). Essa biblioteca será responsável por escrever coisas na tela ou capturar dados enviados pelo usuário.

A linha 2 é um comentário, um trecho de código que não será utilizado pelo compilador, podendo ser documentação, nome do autor do programa, descrição de funcionalidade ou qualquer outra coisa.

A linha 3 representa a inicialização da função main, ou função principal. Tudo que tiver dentro dela será executado quando o computador executar esse programa. O conteúdo dessa função está entre as chaves { e }, nas linhas 4 e 7. A palavra reservada int diz que essa função retornará um inteiro (assim como uma função matemática), e é usado o valor 0 (zero) como valor de retorno padrão para a função main sempre que não houver erros.

A linha 5 chama a função printf, que escreverá o seu conteúdo no console, no caso o nosso “Olá, Mundo”.

A linha 6 indica o retorno da função. Como não tivemos erros na execução, retornaremos 0 (zero).

Para compilar o programa, em Linux, é bem simples. Abra a pasta que você tem salvo o seu arquivo, e use o seguinte comando:

$ gcc Hello.c -o Hello

E para rodar é só você usar o seguinte comando:

$ ./Hello

E pronto, aparecerá a mensagem Olá, mundo! na sua tela.

Gostou do tutorial? Ficou alguma dúvida? Tem algum complemento? Deixa aí nos comentários 😄🥰



odysee

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!
Sort Order:  
  ·  2 years ago  ·  


** Your post has been upvoted (2.00 %) **