DIGIT-ARC read-only archive · snapshot: July 23, 2026

once again i struck with pointers

6 posts · originally from https://geek.digit.in/community/threads/once-again-i-struck-with-pointers.165695/

Ashokkumar01cbe
Ashokkumar01cbe Original post #1
Nov 4, 2012 at 12:15 AM
#include <stdio.h>

#include <math.h>

main()

{

float x,y;

long int i, j, m[6], *k[5] ;

char *letter, *course[3], name [ ] = "I I T Madras";

course[0]="Numerical Methods";

course[1]=" and Programming";

printf ("\n%s %s\n ", course[0], course[1]) ;

for(i=0;i<=5;i++)

m=3*i;

k[0]=&m[1];

k[3]=&m[3];

j=k[3] - k[0];

printf ("\n%d %d %d %d\n ", j, *k, *(k[0]+1), *k[3]) ;

}

i compile this program in a gcc compiler,in this program i struck at the last line that on printing *k as %d it needs to print the first element of the array (ie.. 0) instead it is displaying an address..please help me to solve this .....
W
Windows #2
Nov 4, 2012 at 7:20 AM
First of all, this won't work
Code:
char *letter, *course[3], name [ ] = "I I T Madras";

course[0]="Numerical Methods";

course[1]=" and Programming";

Code:
for(i=0;i<=5;i++)

m[i]=3*i;
You never entered the values in m?
Ashokkumar01cbe
Nov 4, 2012 at 9:25 AM
@windows i have entered the values in m through the for loop.
and also its working.
M
Nov 4, 2012 at 2:35 PM
long int i, j, m[6], *k[5] ;
In this you are declaring k as array of size 5 of pointer to long int.

So, each element of k is pointer to long int. That's exactly what you are getting.

side tip:
If you are doubtful about data types you may try this site.
cdecl
nbaztec
nbaztec #5
Nov 6, 2012 at 8:38 PM
Code:
printf ("\n%d %d %d %d\n ", j, [COLOR="#FF0000"][B]*[/B][/COLOR]*k, *(k[0]+1), *k[3]) ;

And use %ld instead of %d.
gameranand
Nov 7, 2012 at 10:49 AM
First study about pointers and then do the programming, it would really help you.
As for program
What do you really want to do with this program, elaborate, just writing the program and asking is not a good way. You need to tell what you want to do and state your logic which you know about the particular program. :)