Greetings EveryOne
Look at this code;
Code:
#include <stdio.h>
char StringA[] = "Hello, I am Laythe.";
char StringB[30];
int main()
{
char *PointerA;
char *PointerB;
printf("puts(StringA) =\n");
puts(StringA); // Prints StringA on the screen;
printf("\n");
PointerA = StringA;
printf("puts(PointerA) = \n");
puts(PointerA);
printf("\n");
PointerB = StringB; // Line 21;
while(*PointerA != '\0')
{
*PointerB++ = *PointerA++;
}
*PointerB = '\0';
printf("puts(StringB) = \n");
puts(StringB);
printf("\n");
PointerB = StringB; // Line 33;
printf("puts(PointerB) = \n");
puts(PointerB);
return 0;
}
- At line 21, if you comment it or delete it, the compiler will stop compiling at the line.
why is that?
* don't forget to return line 21 as it was if you modified it.
- At line 33, if you comment it or delete it, the value of PointerB is null.
why is that?
* compile the same code with some modifications and you will get a run time error, can you tell me why?
Code:
#include <stdio.h>
char StringA[] = "Hello, I am Laythe.";
char StringB[30];
int main()
{
char *PointerA;
char *PointerB;
printf("puts(StringA) =\n");
puts(StringA); // Prints StringA on the screen;
printf("\n");
PointerA = StringA;
printf("puts(PointerA) = \n");
puts(PointerA);
printf("\n");
PointerB = StringB; // Line 21;
while(*PointerA != '\0')
{
*PointerB++ = *PointerA++;
}
*PointerB = '\0';
printf("puts(StringB) = \n");
puts(StringB);
printf("\n");
PointerB = StringB; // Line 33;
printf("puts(PointerB) = \n");
puts(PointerB);
printf("\n");
printf("*PointerB = %s", *PointerB);
return 0;
}
Thank You In Advance