c - What actually is going on when we do structure type casting? -


here (how cast 1 type in c) have same question without explanation how structure type casting works.

#include <stdio.h> #include <ctype.h>  typedef struct {   int type;   int type2; }foo;  typedef struct {   char cdata[40]; }bar;  int main() {   bar b1;   strcpy(b1.cdata,"11");    (struct foo *) &b1;  // going on here? have changed @ point?   return 0; } 

we have different sizes - sizeof (foo) > sizeof (bar). happened after casting?

you cannot cast 1 structure type another. can cast pointer 1 structure type point another, in case nothing happens it--it's memory address, , re-interpreted pointing different kind of thing.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -