quasimodo
29/12/2006, 17:23
Ben bu pointerlar konusuna acayip takılmış bulunmaktayım. Bir kaç soru sormak istiyorum.
Asagidaki kodda belirtilern hatanın olmasının nedeni nedir ???
#include <stdio.h>
int main()
{
char * p = NULL;
printf("merhaba");
char * s = NULL; //Decleration is not allowed here..
s = "merhaba";
p = s;
puts(p);
}
Fakat boyle yapinca bir hata olmuyor:
#include <stdio.h>
int main()
{
char * p = NULL;
char * s = NULL;
printf("merhaba");
s = "merhaba";
p = s;
puts(p);
}
Yine ayni sekilde belirtilen satirlarda belirtilen hatalari veriyor
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int yerAyir(void)
{
int * p = NULL;
p = (int *) malloc(sizeof(int ) * 5);
int i = 0; //declaration is not allowed here
for(; i < 5; ++i)
*(p++) = i;
return p;
}
int main()
{
int * p = 0;
printf("%d\n", p);
p = yerAyir();
int i = 4; //declaration is not allowed here
for(; i > 0; --i)
printf("%d ", *(p + i));
getch();
return 0;
}
forlarin i tanımlamalarini pointer tanimlamasinin
altinda yapinca düzeliyor
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int yerAyir(void)
{
int * p = NULL;
int i = 0;
p = (int *) malloc(sizeof(int ) * 5);
for(; i < 5; ++i)
*(p++) = i;
return p;
}
int main()
{
int * p = 0;
int i = 4;
printf("%d\n", p);
p = yerAyir();
for(; i > 0; --i)
printf("%d ", *(p + i));
getch();
return 0;
}
Bunlarin nedeni nedir cozebilmis degilim ???
Asagidaki kodda belirtilern hatanın olmasının nedeni nedir ???
#include <stdio.h>
int main()
{
char * p = NULL;
printf("merhaba");
char * s = NULL; //Decleration is not allowed here..
s = "merhaba";
p = s;
puts(p);
}
Fakat boyle yapinca bir hata olmuyor:
#include <stdio.h>
int main()
{
char * p = NULL;
char * s = NULL;
printf("merhaba");
s = "merhaba";
p = s;
puts(p);
}
Yine ayni sekilde belirtilen satirlarda belirtilen hatalari veriyor
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int yerAyir(void)
{
int * p = NULL;
p = (int *) malloc(sizeof(int ) * 5);
int i = 0; //declaration is not allowed here
for(; i < 5; ++i)
*(p++) = i;
return p;
}
int main()
{
int * p = 0;
printf("%d\n", p);
p = yerAyir();
int i = 4; //declaration is not allowed here
for(; i > 0; --i)
printf("%d ", *(p + i));
getch();
return 0;
}
forlarin i tanımlamalarini pointer tanimlamasinin
altinda yapinca düzeliyor
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int yerAyir(void)
{
int * p = NULL;
int i = 0;
p = (int *) malloc(sizeof(int ) * 5);
for(; i < 5; ++i)
*(p++) = i;
return p;
}
int main()
{
int * p = 0;
int i = 4;
printf("%d\n", p);
p = yerAyir();
for(; i > 0; --i)
printf("%d ", *(p + i));
getch();
return 0;
}
Bunlarin nedeni nedir cozebilmis degilim ???