Buscar

When the C/C++ compiler encounters such a situation, it prints a warning (advisory). You, as a programmer, then decide whether the suspicion is jus...

When the C/C++ compiler encounters such a situation, it prints a warning (advisory). You, as a programmer, then decide whether the suspicion is justified. Sometimes false warning messages are generated as a side effect of a real error, but you will undoubtedly encounter many warnings as you continue to write programs in C. 1.4 THE C/C++ LANGUAGE IS CASE-SENSITIVE It is important to know that uppercase and lowercase letters are treated as distinct characters. For example, in some languages, the variable names count, Count, and COUNT are three ways to specify the same variable. However, in the C/C++ language, they will be three different variables. So, when you type programs in C/C++, be careful in the correct use of letters. 1.5 FUNCTIONS IN C The C language is based on the concept of building blocks. The building blocks are called functions. A C program is a collection of one or more functions. To write a program, you first create functions and then put them together. In C, a function is a subroutine that contains one or more statements and performs one or more tasks. In well-written programs, each function performs only one task. Each function has a name and a list of arguments it will receive. In general, any name can be given to a function, except main, which is reserved for the function that starts program execution. A notation convention has become standard when writing about the C language. There will be parentheses after the function name. For example, if the name of a function is max(), it will be written as max() when referenced in the text. This notation will help you distinguish variable names from function names in this text. Here is a first example program in the C language: #include void main(){ printf (“My first program in C!!!
”); } In this example, we have the main() function which, when executed, will display a message on the screen. The message is printed by the printf() function, which receives the message “My first program in C!!!
” as a parameter. The constant “
” at the end of the message means that the cursor should return to the beginning of a new line. A new program, with the same goal, can be written as follows: #include void hello(){ printf (“My first program in C!!!
”); } void main(){ hello(); } In this new program, we created a hello() function, responsible for displaying the message. Note that the hello() function was called from the main() function. 1.5.1 FUNCTIONS WITH ARGUMENTS A function argument is simply a value that is passed to the function when it is called. You have already seen a function that takes an argument: printf(). You can also create functions that pass arguments. For example, the sqr() function in this program takes an integer argument and shows its square: #include int sqr (int x){ //the parameter was declared inside the parentheses printf (“%d squared is %d
”, x, x * x); } void main(){ int num; num = 100; sqr(num); //calls sqr with the num parameter } As you can see in the sqr() declaration, the variable x that will receive the value passed by sqr() is declared inside the parentheses following the function name. Functions that do not pass arguments do not require any variables, so the parentheses are empty. When sqr() is called, the value of num – in this case 100 – is passed to x. Thus, the line “100 squared is 10000” is presented. You should run this program to convince yourself of what it really does, operating as expected. It is important to fix two terms. First, the argument refers to the value that is used to call a function. The variable that receives the value of the arguments used in the function call is a formal parameter of the function. In fact, functions that take arguments

A linguagem C/C++ é case-sensitive.
Uma função é uma sub-rotina que contém uma ou mais declarações e realiza uma ou mais tarefas.
Cada função tem um nome e uma lista de argumentos que receberá.
A função main é reservada para a função que começa a execução dos programas.
Funções que não passam argumentos não necessitam de quaisquer variáveis, de maneira que os parênteses ficam vazios.

Essa pergunta também está no material:

Faculdade_de_Ciencias_Aplicadas_de_Casca
154 pág.

Ciências Aplicadas Universidade Estácio de SáUniversidade Estácio de Sá

💡 1 Resposta

User badge image

Ed Verified user icon

Parece que você está compartilhando informações sobre a linguagem C/C++ e suas características. Se você tiver alguma pergunta específica sobre o assunto, ficarei feliz em ajudar!

0
Dislike0

✏️ Responder

SetasNegritoItálicoSublinhadoTachadoCitaçãoCódigoLista numeradaLista com marcadoresSubscritoSobrescritoDiminuir recuoAumentar recuoCor da fonteCor de fundoAlinhamentoLimparInserir linkImagemFórmula

Para escrever sua resposta aqui, entre ou crie uma conta

User badge image

Outros materiais