declearation of a function body and their execution

shakti's Avatar, Join Date: Mar 2013
Newbie Member
Dear friends,
I am beginner in C programming in Linux. I have one code. I want to learn what will the function give result.
my code is following:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
 int a[4] = {1, 2, 3, 4};
 printf("array element before funtions %d %d %d %d\n", a[0], a[1], a[2], a[3]);
 printf("array element after funtions %d %d %d %d\n", a[0], a[1], a[2], a[3]);
return 0;
void change_val(int *w)
  int n = 4, i = 0;
        w[i] = w[i] + 2;
        printf("%d\n", w[i]);
  printf("array element in funtion %d %d %d %d\n", w[0], w[1], w[2], w[3]);
When I compiled this code and execute, it shows following output:

shakti@shakti-Inspiron-1525:~/Desktop/libicp ./processbyreferece

array element before funtions 1 2 3 4
Segmentation fault (core dumped)

I think only 7th line is executing while there are three more printf options (i.e. 9th, 18th and 21th). My question is how can I rectify this code to execute all printf options. I request to all friends and expert to help me.

Thanks in advance.

shakti kumar
DRK's Avatar
Go4Expert Member
change_val function requires address to int, not int value:
shabbir like this