简体   繁体   中英

Adding floats, integers and to pointer

I'm very new to programming and I have been trying to do the following, but I don't know if I am doing it right.

I have the following declarations

int a, b, c;
int *p1, *p2, *p3;
char d, str[10], *cp;
float big, r;

and with those declarations I have to find out how to declare the following q variables. For example, if *p3 is a integer pointer and r is a float. then what would q1 would have to be. I need to find out how to declare it.

But since each one is of a different type, I don't know how to do it. Some hints would be kindly appreciated

q1 = r + *p3;                     
q2 = &p1 + 5;
q3 = *str + c;
q4 = &str[4];
q5 = *p2;
int a, b, c;
int *p1, *p2, *p3;
char d, str[10], *cp;
float big, r;

So I think the question is to use the declarations above, and the expressions below and come up with a valid set of types for the expressions.

q1 = r + *p3;           
q2 = &p1 + 5; 
q3 = *str + c;  
q4 = &str[4];  
q5 = *p2;        

I think these types are valid for the expressions above:

float q1 = r + *p3;  // float = float + int                   
int **q2 = &p1 + 5;  // int ** = int** + int
int q3 = *str + c;   // int = char + int
char *q4 = &str[4];  // char * = char *
int q5 = *p2;        // int = *int*

q1, q3 and q5 could be any numeric type. I picked the one most obvious to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM