Interview Questions and Answers :: Broadcom Ltd
Home > Experience Archives > Broadcom Ltd > Interview Question Set 2 > Discussion
2. Write a statement which will increment the pointer value to 10 on doing ptr++
int arr[100];
int *ptr;
/* do something here*/
ptr++; // This should incrememnt ptr value by 10 location.
Answer:
int main(){
int x=3;
int *ptr=&x;
printf("%d\n", ptr);
char *p = (char*)ptr;
p+=10; //increments pointer by 10 bytes
ptr = (int *)p;
printf("%d\n",ptr);
}
Amit
12 Apr, 2019 4:26 PM
int main(){
int x=3;
int *ptr=&x;
printf("%d\n", ptr);
char *p = (char*)ptr;
p+=10; //increments pointer by 10 bytes
ptr = (int *)p;
printf("%d\n",ptr);
}
Report Error
Report Error
Please Login First Click Here