Day#26 'C' Coding Challenge

Day#26 'C' Coding Challenge

What is the output of the below code?

#include<stdio.h> int var1 = 100; void main() { char *ptr; ptr = &var1; printf("%d",*ptr);

}

-----------------------------------------------------------

The above code tests the below scenarios:

1. Assigning a pointer 
2. Assigning a pointer of one data type to a variable of another data type

-----------------------------------------------------------

The declared pointer is character type. .................... char *ptr
var1 is integer data type............................................ int var1 = 100
character pointer is assigned integer variable address.
While storing the address is not an issue for any pointer as all pointers point to address of a memory. It is only a problem when value is read. 

Post a Comment

0 Comments