- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to return a local array from a C/C++ function
This is a C++ program return a local array from a function.
Algorithm
Begin We can use dynamically allocated array to return a local array from function Array(). Print the elements of the array. End
Example Code
#include <iostream> using namespace std; int* Array() { int* a = new int[100]; a[0] = 7; a[1] = 6; a[2] = 4; a[3] = 5; return a; } int main() { int* p = Array(); cout <<"The elements are:"<< p[0] << " " << p[1]<<" " <<p[2] << " " << p[3]; return 0; }
Output
The elements are:7 6 4 5
- Related Articles
- How to return local array from a C++ function?
- How to return an array from a function in C++?
- How to access a local variable from a different function using C++ pointers?
- How can we return multiple values from a function in C/C++?
- How can we return multiple values from a function in C#?
- How to return a value from a JavaScript function?
- How to return a string from a JavaScript function?
- C# program to return an array from methods
- How to return a json object from a Python function?
- How to return an object from a JavaScript function?
- Find a local minima in an array in C++
- How to call a JavaScript function from C++?
- How to Call a Lua function from C?
- How to return an object from a function in Python?
- How to return a matplotlib.figure.Figure object from Pandas plot function?

Advertisements