Why is this code working

Why is this code working

Looking at this piece of code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct _point{
  int x;
  int y;
} point;

int main (void)
{

 point *ptr;
 point obj;

 ptr = (point *)malloc(sizeof(char));
 obj.x = 500;
 obj.y = 5000;
 memcpy((void *)ptr, (void *)&obj, sizeof(point));
 printf("point.x = %d, point.y = %d\n", ptr->x, ptr->y);
 return 0;
}

Why is it running correctly when I run it. Shouldn't I get a segfault given I incorrectly do malloc() on sizeof(char) instead of sizeof(point)?

View Answers









Related Tutorials/Questions & Answers:
Why is this code working
Why is this code working  Looking at this piece of code: #include <stdio.h> #include <stdlib.h> #include <string.h> typedef...\n", ptr->x, ptr->y); return 0; } Why is it running correctly when I
Why this is not working...?
Why this is not working...?  import java.util.*; public class Family { int size_of_family=0; public Person[] members=new Person[size_of_family...); f.printOutFamily(); } }   Post the code of Student.java
Advertisements
Multi Threading is not working in that why...?
Multi Threading is not working in that why...?   import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Date; public
Why is urllib2 not working in Python 3.7
Why is urllib2 not working in Python 3.7  Hi, I am trying to use the urllib2 library in Python 3.7, but it is not working. Can anyone explain me? Why is urllib2 not working in Python 3.7? Thanks
Code not working
Code not working  i want to write my first applet. I wrote the java program and html code for that. while im running in appletviewer it is asking for security permissions. so, i created a policy file and linked it with html file
code not working properly
code not working properly  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException...); } } in the above code if i enter a valid username and password i am
why jsp pages are not working on linux but java application is working in windows - JSP-Servlet
why jsp pages are not working on linux but java application is working in windows  java web application jsp pages are not showing the fileds corectly on linux server but same application is working on windows.why
Why does this code prints fAfA instead of fBfA ?
Why does this code prints fAfA instead of fBfA ?  class B { void f(){ System.out.print("fB");} B(){f(); } } public class A extends B...(String[] args) { new A(); }} Why does this code prints fAfA instead
myJSF,Hibernate and Spring integration code is not working. - Hibernate
myJSF,Hibernate and Spring integration code is not working.  the code given in this url : http://www.roseindia.net/roseindiamembers/login.php i have tried but it does not work. when i write http://localhost
My Servlet code not working - Development process
My Servlet code not working  HHi, After executing servlet am getting blank screen. Am using weblogic server and Eclipse editor. But jsp is working fine. Steps(what i did ) 1)Created servlet (In eclipse) and export it (saved
why above code returning the value of squares is 82... even after returning an increnented value of squares... please help me...
why above code returning the value of squares is 82... even after returning an increnented value of squares... please help me...   public class d55 { int squares = 81; public static void main(String
Struts Login Validation. In This code setter of login page is called only one time again it doesnt call it. Why..?
Struts Login Validation. In This code setter of login page is called only one time again it doesnt call it. Why..?  **struts.xml** <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software
UITapgesturerecognizer not working
UITapgesturerecognizer not working  uitapgesturerecognizer not working
Dynamic-update not working in Hibernate.
Dynamic-update not working in Hibernate.  Why is dynamic update not working in hibernate?   Dynamic-update is not working. It means when... am giving you a small block of code for updating of employee detail- public
hibernate.archive.autodetection not working
not working. How to resolve hibernate.archive.autodetection not working issue... and example code. Thanks
Datagrid not working
Datagrid not working  The code here is working fine, apart from the fact that that I'm using netbeans 6.5 and the servlet v2.5 and struts 1.1.... working. please help me out
Why request.getParameter(
Why request.getParameter(  Hi all, I want to to do upload file in my... uploading file is working but data not store in database because my form field value...="POST"> why it happen? Anybody plz help me.. i want use it my project...plz
php <? ?> tag not working
php tag not working  why PHP tags not working in my application?   This might happen when your shortopentag is turned off. So, you...("shortopen_tag", 1); in your code; add the following line to your .htaccess file
UIWebView zoom not working
UIWebView zoom not working  Hi, I don't know why UIWebView zoom not working? Tell the solution. Thanks   Hi, Open the .xib file and set scalesPageToFit to YES. Thanks
calender working in struts - Struts
calender working in struts  when i execute the following code ,that is working properly if i convert to struts html tags that code is not working please help me to rectify the problem
htpasswd working
htpasswd working   hii, What does htpasswd do?   hello,ADS_TO_REPLACE_1 htpasswd creates a new user in a specified group, and asks to specify a password for that user
Why spring?
Why spring?  Why do we need to learn Spring? and where can we use it thanks
html dropdown not working firefox
html dropdown not working firefox  I am writing a Dropdown code in HTML which is not working in firefox. What could be the reason as it's perfectly working in IE and Crome. Thanks
some methods not working on firefox and chrome
some methods not working on firefox and chrome  why some of javascript methods are not working on firefox and chrome? ex : createElement(). Please help me to solve this problem. adv thanx
Why NSMutableDictionary
Why NSMutableDictionary  Why NSMutableDictionary is used for?   NSMutableDictionary inherits from NSDictionary class, which is used to manage mutable associations of keys and values. Actually, NSMutableDictionary
Why System class not in jsp - JSP-Servlet
Why System class not in jsp  Hi Friends, why system.out.println("") not working in jsp . But out.println is working I want the reason pz . Thanks Prakash
getElementById not working
guess why? I always thought getElementById was a better way of doing
JQuery-event working new element
JQuery-event working new element  I want to know- why not an event(in JQuery) works on my created element through jQuery
calculate working hour
calculate working hour  why echo not come out? <html><body> <form action="<?php $_SERVER['PHP_SELF'];?>" method="post"> Working hour : <input name="workout" type="text"/><input name="submit1
why this can't
why this can't  import java.util.*; class Dash{ public static void main(String args[]){ int x0=100; int[] x1=new int[3]; int[][] x2=new int[3][3]; int[][][] x3=new int[3][3][3
data science for working professionals
data science for working professionals  Hi, I am beginner in Data...: data science for working professionals Try to provide me good examples or tutorials links so that I can learn the topic "data science for working
Update not working in hibernate.
Update not working in hibernate.  Update not working in hibernate
Comparing arrays not working correctly?
Comparing arrays not working correctly?  Comparing arrays not working correctly
Nitobi Grid is not working in IE10/IE11
Nitobi Grid is not working in IE10/IE11  Nitobi grid is working in IE8, but not working in IE10/IE11. we are using above two javascript files to open the grid
Your hibernet tutorial is not working - Hibernate
location http://www.roseindia.net/hibernate/firstexample.shtml it working..., Plz specify in detail. you are created three table but why? plz send me code. Thanks
why jre in jdk
why jre in jdk  why jre in jdk
Focus method not working in firefox
Focus method not working in firefox  object.focus() is not working in firefox and chrome the element is not focused what was the problem
working of a div tag in html
working of a div tag in html   !DOCTYPE html PUBLIC "-//W3C//DTD...; This is a simple code. but after executing it i am not getting the sentence "content for new Div Tag goes here" in red block. why it is happening like
StandardServiceRegistryBuilder not working in Hibernate 4.3.1
StandardServiceRegistryBuilder not working in Hibernate 4.3.1  Hi, It seems that the StandardServiceRegistryBuilder not working in Hibernate 4.3.1. I don't know what is wrong with the following code: Configuration cfg = new
ModuleNotFoundError: No module named 'working'
ModuleNotFoundError: No module named 'working'  Hi, My Python... 'working' How to remove the ModuleNotFoundError: No module named 'working... to install padas library. You can install working python with following command
ModuleNotFoundError: No module named 'working'
ModuleNotFoundError: No module named 'working'  Hi, My Python... 'working' How to remove the ModuleNotFoundError: No module named 'working... to install padas library. You can install working python with following command
ModuleNotFoundError: No module named 'working'
ModuleNotFoundError: No module named 'working'  Hi, My Python... 'working' How to remove the ModuleNotFoundError: No module named 'working... to install padas library. You can install working python with following command
xor operator not working correctly with array
xor operator not working correctly with array  main { int a[2...] ^= a[0]; //a[0] ^= a[1]; //this is working correctly. a[0] ^= a[1] ^= a[0] ^= a[1]; //this didn't work correctly why? printf("after swapping: %d %d\n
xor operator not working correctly with array
xor operator not working correctly with array  main { int a[2...] ^= a[0]; //a[0] ^= a[1]; //this is working correctly. a[0] ^= a[1] ^= a[0] ^= a[1]; //this didn't work correctly why? printf("after swapping: %d %d\n
Working Example for Spring AOP - Spring
Working Example for Spring AOP  Hi All, I need a complete working Java example /Code/Logic for Spring -Aspect Oriented Programming. Code provided will be highly appreciated. -- Deepak Lal
Why it called Struts?
Why it called Struts?  Why it called Struts
why the php is open source?
why the php is open source?  why the php is open source
why using static keyword
why using static keyword  why using static keyword
Why is super.super.method(); not allowed in Java?
Why is super.super.method(); not allowed in Java?  Why is super.super.method(); not allowed in Java
why not float main?
why not float main?  why should the main be int or void?why cant it be float or char? why int main()?why not float main()?or char main

Ads