I've started to learn pointers, but I am not sure how pointer's operations work. Can you demonstrate on this piece of code how can I use pointers in practice
Thanx in advance!
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
void main()
{
int i;
int z;
int b = 0;
char ch[250];
printf("%s\n", " Enter line not longer than 250 characters");
gets_s(ch);
for (i=0; i<10; i++)
{
if (i>4)
{
z = i;
b++;
break;
}
}
printf("%d%c", b, ch[z]);
}
What I have done so far, I've tried to use pointers with the same code, get no errors, but the program suddenly feezes in the execution process
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
void main()
{
int i;
int *i2;
i2 = &i;
int z;
int *z2;
z2 = &z;
int b = 0;
int *b2;
b2 = &b;
char ch[250];
//char *ch2;
//ch2 = &ch;
printf("%s\n", " Enter line not longer than 250 characters");
gets_s(ch);
for (*i2 = 0; *i2<10; i2++)
{
if (*i2>4)
{
*z2 = *i2;
*b2++;
break;
}
}
printf("%d%c", *b2, ch[*z2]);
}