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



Home Answers Viewqa Development-process Why is this code working
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


fabrizio
Why is this code working
0 Answer(s)      3 years and 3 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
UITapgesturerecognizer not working
UITapgesturerecognizer not working  uitapgesturerecognizer not working
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
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
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 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
Why spring?
Why spring?  Why do we need to learn Spring? and where can we use it thanks
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
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
getElementById not working
guess why? I always thought getElementById was a better way of doing
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
 

 

 

DMCA.com