Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Development-process Why is this code working

Have Programming Question? Ask it here!
 
 
 


fabrizio
Why is this code working
0 Answer(s)      2 years and 11 months ago
Posted in : Development process


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)?


Advertisement
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
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
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
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
Why spring?
Why spring?  Why do we need to learn Spring? and where can we use it thanks
htpasswd working
htpasswd working   hii, What does htpasswd do?   hello, htpasswd creates a new user in a specified group, and asks to specify a password for that user
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
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
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
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
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
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
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 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
why jre in jdk
why jre in jdk  why jre in jdk
Comparing arrays not working correctly?
Comparing arrays not working correctly?  Comparing arrays not working correctly
Update not working in hibernate.
Update not working in hibernate.  Update not working in hibernate
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
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
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
why java is securable ?
why java is securable ?  why java is securable ?   Hi... readability as it contains byte code understandable only to JVM. 2)The byte code.... 3) No virus will infect the byte code. Thanks
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 using static keyword
why using static keyword  why using static keyword
why the php is open source?
why the php is open source?  why the php is open source
Why it called Struts?
Why it called Struts?  Why it called Struts
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
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
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
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 servlet as controller - Struts
why servlet as controller   Hi Friends, Main reasons for using servlet as a controller in struts. why not jsp . Thanks Prakash  Hi... the code that is written in JSP willbe converted finall into Servlet. A single
Why NSString Objective C
Why NSString Objective C  Why we use the NSString class in Objective C and how to define and initialize the NSString Class?   Why NSString..." "This is line 2"; In the last see the code to append
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
Java is an opensource program or not? why???
Java is an opensource program or not? why???  Java is an open source program or not.. why
Why "<![CDATA[ ]]>" CDATA tag.
Why tag.  . Why do we use this tag and what is the name of this tag
Why Ajax for web?
Why Ajax for web?  Hi, Why Ajax is so important in web applications development? Thanks
file_exists php not working
file_exists php not working  file_exists php not working. Please give me the simple example
 

 

 

DMCA.com