c - Casting char pointer to int pointer - buffer error 10 -


In this, the author discussed how Potter could be put in C. I want to try and create this code:

  #include & lt; Stdio.h & gt; Int main (zero) {four * C; * C = 10; Int i = * (int *) (C); Printf ("% d", i); Return 1; }   

This compile (with a warning) and when I execute the binary, it only outputs just error: 10 . I understand that a letter is a small size from an int I also understand that I should expect this error. But I really appreciate it if someone can clarify what's going on here. Apart from this, I want to know that Pointer is the right way to insert and dereference (in this example) to get 10 points for the int pointer. Thanks!

EDIT: If you're worried, to clarify my intentions, I'm just trying to come up with the "work" example of casting casting. It's just to show that this permission is allowed and may be work in C.

C is unearned when you defer this undefined behavior is.

Similarly, even if the c was initialized, your typecast's int * and then a < P> A work (secure) example shows what you are doing:

  int main (zero) {int i = 10; Int * p = & amp; I; Four c = * (four *) p; Printf ("% d \ n", c); Return 0; }   

This program will print 10 on a small-endian machine and 0 on a large Andian machine.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -