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:
Code:
#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]);
change_val(a[4]);
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;
while(i<n)
{
w[i] = w[i] + 2;
printf("%d\n", w[i]);
i++;
}
printf("array element in funtion %d %d %d %d\n", w[0], w[1], w[2], w[3]);
}
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
