

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why doesn't C++ support functions returning arrays
Let us consider this following program,
#include <iostream> using namespace std; int* Array() { int a[100]; a[0] = 7; a[1] = 6; a[2] = 4; a[3] = 3; return a; } int main() { int* p = Array(); cout << p[0] << " " << p[1]<<" "<<p[2]<<" "<<p[3]; return 0; }
In this program,We get warning as,
Output
In function 'int* Array()': warning: address of local variable 'a' returned [-Wreturn-local-addr] int a[100];
We return the address of local variable but this is not possible as local variable may not exist in memory after the end of function call. So, C++ doesn’t support function returning arrays.
- Related Questions & Answers
- Why doesn't JavaScript support multithreading?
- Why doesn't MySQL support millisecond / microsecond precision?
- Python3 - Why loop doesn't work?
- Why Training Doesn’t Help Your Organization!
- Why doesn't JavaScript have a goto statement?
- Why C/C++ variables doesn’t start with numbers
- Why does C++ require a cast for malloc() but C doesn't?
- Why final variable doesn't require initialization in main method in java?
- Why subclass doesn't inherit the private instance variables of superclass in Java?
- MySQL system variable table_type doesn't work?
- Does C++ support Variable Length Arrays
- Does Java support multi-dimensional Arrays?
- jQuery .val change doesn't change input value?
- Why aren't variable-length arrays part of the C++ standard?
- Why JavaScript 'var null' throw an error but 'var undefined' doesn't?
Advertisements