Home » Learn C++

Returning Structure from Functions

Returning Structure from Functions
Returning Structure from Functions:             Since a structure type data can be passed to a function, a function can also return a structure type data. Usually, the structure type data returned by a function is assigned to a structure type variable. For example: Program:   # include <iostream.h> # include <conio.h> # include <stdio.h> struct temp { char mn[12]; float... 

Returning Data from Functions

Returning Data from Functions
Returning Data from Functions:             A function can return only one value. It can be of any type except string and array. The type of data that a user-defined function returns is declared in function declaration. The value or data is returned from the function to the calling function by the “return” statement.   Return Statement:             The “return” statement... 

Passing Structure to Functions

Passing Structure to Functions
Passing Structures to Functions:             The structures can also be passed as arguments to a function. If a structure is to be passed to a function, then it must be defined before the declaration of the function that uses the structure type data as argument. The program example given below explains the use of structure type data as argument of a function.   Program:            ... 

C++ Array Arguments

C++ Array Arguments
Passing Array as Arguments to a Function:             An array variable can also he passed to the function as an argument. When an array is passed to the function only the starting address of the array is passed to the function. The C++ does not make a separate copy of the array in the body of the function. It only assigns the starting address of the same memory area of the array to the... 

Passing Arguments to Function

Passing Arguments to Function
Passing Arguments to Functions:             If a function needs data to perform a specific task, this data is provided through the arguments of the function. The arguments are placed in parentheses. The arguments are either constants or variables. They are written in the same sequence in which they are defined in the function declaration. The data type of an argument in the function call... 

Calling a Function

Calling a Function
Calling a Function:             Executing the statements of a function to perform a task is called calling of the function. A function is called by referencing its name. The parameters (if any) of the function are given in parentheses after the name of the function. If a function has no parameters then the parentheses are left blank. If a function has a return value of numeric type then... 

Function Declaration (Prototype)

Function Declaration (Prototype)
Function Declaration (Prototype):             The function declaration is also called prototype. Prototype means sample or model. The function declaration only provides the model of the function. Since function declaration provides the model of the function, it is called prototype. In function declaration, the following information about the function is provided to the compiler: • The... 

Functions in C++

Functions in C++
Functions in C++:             A function is a set of instructions that are designed to perform a specific task. A function is a complete and independent program. It is executed by the main function or any other function of the program to perform its task.             The functions are written to write the code of a large program by dividing it into smaller units. When a program... 

Array of Pointers

Array of Pointers
Array of Pointers:   Pointer variables may also be declared as an array.   When an array of strings is declared without using a pointer then each element of the array has a fixed length. If the string entered is shorter than the length of the element, then the remaining space of the element cannot be used. Thus memory space is wasted. To solve this problem, the array of strings is declared by using... 

Pointers and Strings

Pointers and Strings
Pointers and Strings:   A string is a sequence of characters. A string type variable is declared in the same manner as an array type variable is declared. This is because a string is an array of character type variables.   Since a string is like an array, pointer variables can also be used to access it. For example:   char st1[ ] = “Pakistan”; char *st2 = “Pakistan”;   In the above statements,... 
Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Copyright © 2010 Information Village. All rights reserved.