Register and join over 40,000 other developers!
Recent Topics
-
Tekken 7
IsrealJones - Mar 22 2021 07:21 AM
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
New to the community
iwinx - Jul 17 2020 12:02 PM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

3 replies to this topic
#1
Posted 27 November 2008 - 09:45 AM
(i m a student
our placements are going on
last week HP visited our campus
in the technical round they asked me this question)
union a{
some data;
};
mem=malloc(80);
and there is some data copied to the mem variable
now how one can map the mem to a
our placements are going on
last week HP visited our campus
in the technical round they asked me this question)
union a{
some data;
};
mem=malloc(80);
and there is some data copied to the mem variable
now how one can map the mem to a
#2
Posted 27 November 2008 - 11:52 AM
something like this should work i guess:
union a *new = NULL; mem=malloc(80); if(mem != NULL) { new = (union a*)(&mem); }
#3
Posted 27 November 2008 - 10:06 PM
That's not correct, since mem would have to be a pointer. That would assign the data beginning with mem somewhere in memory to the pointer. And you can't use new as a variable in C++, so I wouldn't use that either.
typedef union { /*some stuff*/ }A; void *mem = malloc(/*arbitrary size*/); A *myunion = (A *)mem;
#4
Posted 27 November 2008 - 11:30 PM
ahh yeah indeed mem would have to be a pointer
well about the new i assumed c but yeah its better to avoid it
well about the new i assumed c but yeah its better to avoid it
Also tagged with one or more of these keywords: malloc
![]() ".exe has stopped working"Started by AkhileshJain, 22 Jul 2014 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
malloc or not to mallocStarted by fyr, 23 Jan 2013 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Dynamic Arrays: Using malloc()Started by china, 11 Sep 2012 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Using malloc() and realloc() for a variable-length stringStarted by DarkLordCthulhu, 17 Mar 2011 ![]() |
|
![]() |
||
Tutorial Forums →
C/C++ Tutorials →
malloc(); in C [Short tutorial]Started by lionaneesh, 08 May 2010 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download