Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Funciones Con Argumentos | Introducción a las Funciones
Introducción a C++
course content

Contenido del Curso

Introducción a C++

Introducción a C++

1. Para Comenzar
2. Variables y Tipos de Datos
3. Introducción a los Operadores
4. Introducción al Flujo de Programas
5. Introducción a las Funciones

Funciones Con Argumentos

Una función con parámetro (argumento) es una función que tiene que trabajar con un objeto "desde fuera".

Nota

Un argumento de función es una variable local creada y existe sólo en la función actual.

Por ejemplo, creemos una función que divida cualquier entero por 2:

Para utilizar una función de este tipo, es necesario llamarla y pasarle un argumento:

Aquí tienes un ejemplo:

Puede pasar varios argumentos a una función:

Por ejemplo, vamos a crear una función que divida cualquier entero por 2:

func(5, 7) - llamar a una función y pasarle argumentos. Los argumentos se pasan con comas (,).

También puedes pasar arrays:

Para utilizar una función de este tipo, necesitas llamarla y pasarle un argumento:

He aquí un ejemplo:

cpp

main

copy
12345678910111213
#include <iostream> int func(int argument) { int result = argument / 2; return result; } int main() { //function calling and passing it an argument std::cout << "func() returned: " << func(10); }

Puedes pasar múltiples argumentos a una función:

cpp

main

copy
1234567891011
#include <iostream> int func(int a, int b) { return a + b; //the function to sum arguments } int main() { std::cout << "sums the arguments = " << func(5, 7); }

func(5, 7) – llamando a una función y pasando argumentos a la misma. Los argumentos se pasan con comas (,). También puedes pasar arreglos:

cpp

main

copy
123456789101112131415
#include <iostream> //the size of the passed array is optional int func(int arrayForFunc[]) { return arrayForFunc[2]; //function will returned third element } int main() { int array[6] = { 75, 234, 89, 12, -67, 2543 }; //calling function std::cout << "Third element of array is: " << func(array); }

¿Todo estuvo claro?

Sección 5. Capítulo 4
We're sorry to hear that something went wrong. What happened?
some-alt