How to Pass an Array to Function

C code for passing array to a function and returning pointer from function.
#include<stdio.h>
#include<stdlib.h>
void func(int *arr, int n);
int main()
{
int i;
int arr[]={1,2,3,4,5};

    printf("\nArray element after function : \n");
func(arr,5);//its a pass by reference only as name of the arry is the base address
    for(i=0;i<5;i++)
    {
        printf("%d ",arr[i]);//11 12 13 14 15
    }
    printf("\n");
    return 0;
}
void func(int *p, int n)
{
int *arr=p;
    int i;
    for(i=0;i<n;i++)
    {
        arr[i]=p[i]+10;
    }

}//end of main

Example 2:
/*
   c code to pass array to a function
 */
#include<stdio.h>
#include<stdlib.h>
int* func(int *arr, int n);
int main()
{
int i;
int arr[]={1,2,3,4,5};
int *p;
p=func(arr,5);
    printf("\nArray element after function : \n");
    for(i=0;i<5;i++)
    {
        printf("%d ",p[i]);//11,12,13,14,15
    }
    printf("\n");
    return 0;
}
int* func(int *arr, int n)
{
    int i;
    int *p=arr;
    p=(int *)malloc(n*sizeof(int));
    for(i=0;i<n;i++)
    {
        p[i]=arr[i]+10;//arr[i] is must not p[i]
    }
    return p;
}

Example 3: not a good program
/*
   c code to pass array to a function
 */
#include<stdio.h>
#include<stdlib.h>
int* func(int *arr, int n);
int main()
{
    int i;
    int arr[]={1,2,3,4,5};

    printf("\nArray element after function : \n");
    func(arr,5);
    for(i=0;i<5;i++)
    {
        printf("%d ",arr[i]);//1 2 3 4 5
    }
    printf("\n");
    return 0;
}
int*  func(int *p, int n)
{
    int *arr=p;
    arr=(int *)malloc(n*sizeof(int));
    int i;
    for(i=0;i<n;i++)
    {
        arr[i]=arr[i]+10;//arr[i] is must not p[i]
    }
    return arr;/*if returning a pointer then function should have been called from a pointer */

}

Pointer to Array of Pointers in C

C Code for pointer to array of char* ie pointer to strings.
#include<stdio.h>
int main()
{
    /*array of strings*/
char arr[3][10]={
            "Ram",/*first string ie first char array*/
            "Bhagwan",
            "Yeshu"
            };
/*pointer to array.Each array is 1-d array of chars ie each array is string*/
char (*p)[10];
p=(char *)arr;/*  p=arr+0 so p first points to first char array ie first string Ram*/

char* pp;

How to use Pointer to An Array of Integers in C

What is Pointer to an Array in C?
int (*p)[4];//p is pointer to array and each array is having 4 its
 so,p points to base address of first array ie address of other elements of first array.
 p+1 points to base address of second array and not the 1st element of first array.
 p+2 points to base address of third array  and not the 2nd element of first array.
 To access the individual elements of each array:
 assign the pointer to array to a pointer to int here pp and access through *(pp+i).

#include<stdio.h>
int main()
{
    /*array of strings*/
    int arr[3][4]={
        {0,1,2,3},/*first string ie first char array*/
        {4,5,6,7},
        {8,9,1,2},
    };
    /*pointer to array.Each array is 1-d array of chars ie each array is string*/
    int (*p)[4];
    p=(int *)arr;/*  p=arr+0 so p first points to first char array ie first string Ram*/

    int* pp;

Pointer to use Array of Integers in C

How to use pointer to an array of integers:
 int a[]={10,20,30};//array of ints
 int (*p)[3];//p is pointer to array
 so if int *q=p then
 q points to first array {10,20,30}
 q+1 points to second array {garbage here}
 q+2 points to third array {garbage here}

Note:here only one 1-d array so using pointer to array is not useful.
So, generally pointer to array is used with multdimensional arrays

/*
 example of pointer to array, best with 2-d array as 2d array is array of multiple 1-d arrays

 int a2d[3][3]={//rray of three 1-d arrays each having 3 element
     {10,20,30},
     {40,50,60},
     {70,80,90}
 };
 int (*ptr)[3];//ptr is pointer to array of 3 ints so contins address
 ptr=a2d;
 */
 /*first row of 2d array is first 1-d array. ptr+0 contains the base address of first array{10,20,30}; */
 /*second row is second array ptr+2 contains the base address of second array{40,50,60};*/
 /*third row is third array ptr+2 contains the base address of third array{70,80,90};*/
/*
 so incremting ptr++ will give the base address of next array and not the next element of first array and so on
 so check how to access individual elements of array using pointer to array at last of code
 */
#include<stdio.h>
int main()
{
 int a[]={10,20,30};//array of ints
 int (*p)[3];/*p is pointer to array of 3 ints so contins address*/

 p=a;

Array of Strings in C

Array of pointers to string.First its important to recall what is string in C? In C string is an array of characters terminated by \0.string can be represented in two ways:
 char str[]="Hello";//str is string
 or
 char* str="Hello";//here str is pointer so it stores the base address of the string ie base addrees of the array of characters.

 So, Now its quite clear that array of pointer to string means array of base addresses of strings.

 char* stra[]={"Programmer","are","Great"};//stra is array of pointers.

 so stra[0] contains base address of "Programmers".
 so stra[1] contains base address of "are".
 so stra[2] contains base address of "Great".

full Example code:

How to use Array of integer Pointers in C

Array of pointers to integers.i.e.Array of integer pointers.Since,Integer pointer store address of one integer.Therefore,Array of pointers to integers will store addresses many integers.
#include<stdio.h>
int main()
{
    int a[]={10,20,30};/*array of integers*/
    int* arr[]={a,a+1,a+2};/*array of integer pointers so contains addresses*/
 
    printf("\nAddresses of integers:\n");
    printf("address of a=%u\n",a);/*no & needed as name of the array gives base address.*/
    printf("address of a+1=%u\n",(a+1));
    printf("address of a+2=%u\n",a+2);

    printf("\nAddrs of integers are stored in arr so each arr[i] is an address:\n");
    printf("arr[0]=%u\n",arr[0]);
    printf("arr[1]=%u\n",arr[1]);
    printf("arr[2]=%u\n",arr[2]);

Array of Pointers to integer in C

/*Array of pointers to integers i.e. Array of integer pointers. Since integer pointer store one address.So,array of integer pointers is used to store  many addresses .*/
#include<stdio.h>
int main()
{
    printf("\nBefore starting array of pointers Understand pointer \n");
    printf("\nint *p; tells to compiler that p will be used to store single address of integer\n");
    int *p;//p will be used to store address of a pointer
    int i=10;
    p=&i;//pointer is used to store address of int i
    printf("address of i=%u or p=%u\n",&i,p);
    printf("value of i=%d or *p=%u\n",i,*p);


    printf("\nNow understanding array of pointer to integers.\n");
    printf("\narray of pointers to integers is used to store many addresses of integers\n");
    int a=10,b=20,c=30;
    int* arr[]={&a,&b,&c};/*arr is array of integer pointers so contains addresses*/
 
    printf("\nAddresses of integers:\n");
    printf("address of a=%u\n",&a);
    printf("address of b=%u\n",&b);
    printf("address of c=%u\n",&c);

Circular Queue, Circular linked list

/*linked list as circular queue*/
#include<stdio.h>
#include<stdlib.h>
struct node
{
    int data;
    struct node *next;
};

void addq(struct node **f, struct node **r, int d);
void deleteq(struct node **f, struct node **r);
void display(struct node *f);

Singly linked list all operations by passing head

/*Code for:
  linked list through head
  1.insert at beginning
  2.inser after given position
  3.inser at end/append
  4.display
  5.reverse
  6.delete from beginning
  7.delete the given node value
  8.countnumber of nodes
 */
#include<stdio.h>
#include<stdlib.h>
struct node
{
    int data;
    struct node *next;
};
struct node *head;//*head is start

void insertBegin(struct node **head, int d);
void insertPosition(struct node **head, int position, int data);
void insertEnd(struct node **head, int d);
void display(struct node *head);
void count(struct node *head);
void reverse(struct node **head);
void deleteBeginning(struct node **head);
void deleteKey(struct node **head);

Linked list all operations without head pass in c

/*   code for single linked list operations:
   1.insert at Begin
   2.insert at Last//append
   3.Insert at Given Position
   4.Display
   5.reverse
   6.delete at beginning
   7.delete given node
 */
#include<stdio.h>
#include<stdlib.h>

struct node
{
    int data;
    struct node *next;
};
struct node *start;

void insertAtBegin(int d);
void insertAtLast(int d);
void insertAtPosition(int d,int p);
void display();
void reverse();
void deleteAtBegin();
void deleteKey();
void count();