- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Found 34470 Articles for Programming
![Jennifer Nicholas](https://www.tutorialspoint.com/assets/profiles/13569/profile/60_88876-1512715262.jpg)
391 Views
Pointers and array most of the time are treated as same in c. Some differences are:&operator:&pointer = returns the address of pointer.&array = returns the address of first element.sizeof operator:sizeof(array) = returns the total memory consumed by the all the elements of the array.sizeof(pointer) = returns the only memory consumed by the pointer variable itself.Array variable can’t be re-assigned a value whereas pointer variable can.Declaration:int a[]; //array Int *p; //pointerLet us consider that there is an integer pointer variableint *i;Now let us consider the outcome of the following assignments –a = &i; //illegal assignment. a variable can not be updated ... Read More
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
235 Views
C treats array parameter as pointers because it is less time consuming and more efficient. Though if we can pass the address of each element of the array to a function as argument but it will be more time consuming. So it’s better to pass the base address of first element to the function like:void fun(int a[]) { … } void fun(int *a) { //more efficient. ….. }Here is a sample code in C:#include void display1(int a[]) //printing the array content { int i; printf("Current content of the array is: "); for(i = 0; i < ... Read More
![Jennifer Nicholas](https://www.tutorialspoint.com/assets/profiles/13569/profile/60_88876-1512715262.jpg)
341 Views
If there are repeated values are present in C then we use shorthand array notation to define that array.Here is an example:Example Code#include int main() { int array[10] = {[0 ... 3]7, [4 ... 5]6,[6 ... 9]2}; for (int i = 0; i < 10; i++) printf("%d ", array[i]); return 0; }Output7 7 7 7 6 6 2 2 2 2In this program,int array[10] = {[0 ... 3]7, [4 ... 5]6,[6 ... 9]2}is similar as,int array[10] = {7, 7, 7, 7, 6, 6, 2, 2, 2, 2}.If there is any gap in the middle of the array it will be filled up by 0.In C++ above program will give the same output but it will give warnings with the output.
![Nitya Raut](https://www.tutorialspoint.com/assets/profiles/13573/profile/60_92249-1512715559.jpg)
1K+ Views
Flexible Array members in a structure in C means we can declare array without its dimension within a structure and its size will be flexible in nature. Flexible array member must be the last member of class.Here is an example:Example#include #include #include //structure of type employee and must contain at least one more named member in addition to the flexible array member. struct employee { int emp_id; int name_len; int emp_size; //‘emp_size’ variable is used to store the size of flexible character array emp_name[]. char emp_name[]; //Flexible array member emp_name[] should be the last member ... Read More
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
238 Views
C++ does not allow to pass an entire array as an argument to a function. However, you can pass a pointer to an array by specifying the array's name without an index.If you want to pass a single-dimension array as an argument in a function, you would have to declare function formal parameter in one of following three ways and all three declaration methods produce similar results because each tells the compiler that an integer pointer is going to be received.Method-1Formal parameters as a pointer as follows −void myFunction(int *param) { . . . }Method-2Formal parameters as ... Read More
![Jennifer Nicholas](https://www.tutorialspoint.com/assets/profiles/13569/profile/60_88876-1512715262.jpg)
2K+ Views
Here is a C++ program to initialize a dynamic array. Here in this program we can use dynamically allocated array to return a local array from the function Array().Example Code Live Demo#include 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
![Nitya Raut](https://www.tutorialspoint.com/assets/profiles/13573/profile/60_92249-1512715559.jpg)
8K+ Views
In programming language, sorting is a basic function which is applied to data to arrange these data is ascending or descending data. In C++ program, there is a function std::sort() for sorting the array.sort(start address, end address)Here,Start address => The first address of the element. Last address => The address of the next contiguous location of the last element of the array.Example Code Live Demo#include #include using namespace std; void display(int a[]) { for(int i = 0; i < 5; ++i) cout
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
6K+ Views
If we pass the address of an array while calling a function, then this is called function call by reference. The function declaration should have a pointer as a parameter to receive the passed address, when we pass an address as an argument.Example Code Live Demo#include using namespace std; void show( int *num) { cout