Question:
C programming, source code question?
AyHpt
2011-05-02 05:25:40 UTC
I have this pieces from a program and i need to figure if there are any errors here... if so can you tell me why? i'm trying to study for an upcoming test and i need this for practice and understand why. Anyone? Thanks

a) int *number; /*This has a problem because the point has to be defined right?*/
printf ("%d\n", *number);

b) float *realPtr;
long *integerPtr;
integerPtr = realPtr;

c) int * x, y;
x=y;

d) char s[] = "this is a character array";
int count;
for ( ; *s != '\0' ; s++) /*the for loop need the {} right??*/
printf("%c " , *s);

e) short *numPtr, result;
void *genericPtr = numPtr;
result = *genericPtr + 7;

f) float x= 19.34;
float xPtr = &x;
printf ("%f\n", xPtr);

g) char *s;
printf("%s\n", s);
Three answers:
2011-05-02 06:13:11 UTC
a) Yes, number doesn't point anywhere. You can fix this by doing:



int *number;

int n = 5;



number = &n;

printf("%d\n", *number);



b) That doesn't work at all. (float *)s point to floats. (long *)s point to longs. (float **)s point to (float *)s.



c) x = &y;



d) You can't increment arrays like you can with pointers. The program can be written as:



#include



int main()

{

char s[] = "this is a character array";

char *sp;



for(sp = s; *sp != '\0'; ++sp)

printf("%c ", *sp);

return 0;

}



e) You can't dereference a (void *) since it has no defined size. numPtr doesn't point anywhere.



f) xPtr isn't a pointer, it's a float. You shouldn't store addresses in floats. float *xPtr = &x; and printf("%f\n", *xPtr); or printf("%p\n", xPtr);



g) s doesn't point anywhere.
wiesner
2016-10-18 11:10:50 UTC
i'm going to offer you a great clue: This application includes 3 aspects: a million. Get the enter from the person. 2. choose, based on the indications of the coordinates, which quadrant the element is in. bigger hint: one thank you to try this's a single, 4-branched, IF fact. 3. rfile the outcomes to the person. it extremely is spoke of as issue prognosis, and you have gotta get a cope with on it to application. wish that helps.
2011-05-02 05:27:14 UTC
The Jews (Hebrew: יְהוּדִים‎‎ ISO 259-3 Yhudim Israeli pronunciation [jehu'dim]), also known as the Jewish people, are a nation and ethnoreligious group originating in the Israelites or Hebrews of the Ancient Near East. The Jewish ethnicity, nationality, and religion are strongly interrelated, as Judaism is the traditional faith of the Jewish nation.[6][7][8] Converts to Judaism, whose status as Jews within the Jewish ethnos is equal to those born into it, have been absorbed into the Jewish people throughout the millennia.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...