int i = 10;
void *j = &i;
How to print out the integer "10" ?
Thanks. 5 2320
howa wrote:
int i = 10;
void *j = &i;
How to print out the integer "10" ?
#include <iostream>
int main() { std::cout << 10 << std::endl; }
Or where you asking something else?
--
Ian Collins.
Alf P. Steinbach wrote:
* howa:
>int i = 10; void *j = &i;
How to print out the integer "10" ?
#include <iostream>
int main
{
std::cout << "10" << std::endl;
}
Echo?
--
Ian Collins.
On 1$B7n(B24$BF|(B, $B2<8a(B4$B;~(B08$BJ,(B, "Alf P. Steinbach" <al...@start.nowrote:
* howa:
int i = 10;
void *j = &i;
How to print out the integer "10" ?
Technically the answer is to cast the pointer and dereference it,
*static_cast<int*>(j).
However, as a novice you should not use raw pointers at all, much less
void* pointers: what's the problem you're trying to use void* to solve?
How does the following one compare with static_cast?
e.g. cout<< *(int*)j;
Howard
howa wrote:
On 1$B7n(B24$BF|(B, $B2<8a(B4$B;~(B08$BJ,(B, "Alf P. Steinbach" <al...@start.nowrote:
>* howa:
>>int i = 10; void *j = &i; How to print out the integer "10" ?
Technically the answer is to cast the pointer and dereference it, *static_cast<int*>(j).
However, as a novice you should not use raw pointers at all, much less void* pointers: what's the problem you're trying to use void* to solve?
How does the following one compare with static_cast?
e.g. cout<< *(int*)j;
It's harder to search for in code and more likely to hide errors (the
compiler will reject inappropriate use of static_cast).
--
Ian Collins.
On 1$B7n(B24$BF|(B, $B2<8a(B5$B;~(B44$BJ,(B, Ian Collins <ian-n...@hotmail.comwrote:
howa wrote:
On 1$B7n(B24$BF|(B, $B2<8a(B4$B;~(B08$BJ,(B, "Alf P. Steinbach" <al...@start.nowrote:
* howa:
>int i = 10; void *j = &i; How to print out the integer "10" ?
Technically the answer is to cast the pointer and dereference it,
*static_cast<int*>(j).
However, as a novice you should not use raw pointers at all, much less
void* pointers: what's the problem you're trying to use void* to solve?
How does the following one compare with static_cast?
e.g. cout<< *(int*)j;
It's harder to search for in code and more likely to hide errors (the
compiler will reject inappropriate use of static_cast).
--
Ian Collins.- $Bp,i6Ho0zMQJ8;z(B -
- $Bp}<(Ho0zMQJ8;z(B -
Thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stig Brautaset |
last post by:
Hi group,
I'm playing with a little generic linked list/stack library, and have a
little problem with the interface of the pop() function. If I used a
struct like this it would be simple:
...
|
by: bob_jenkins |
last post by:
{
const void *p;
(void)memset((void *)p, ' ', (size_t)10);
}
Should this call to memset() be legal? Memset is of type
void *memset(void *, unsigned char, size_t)
Also, (void *) is the...
|
by: infobahn |
last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
|
by: Juggernaut |
last post by:
I am trying to create a p_thread
pthread_create(&threads, &attr, Teste, (void *)var);
where var is a char variable.
But this doesnt't work, I get this message:
test.c:58: warning: cast to pointer...
|
by: Stijn van Dongen |
last post by:
A question about void*. I have a hash library where the hash create
function accepts functions
unsigned (*hash)(const void *a)
int (*cmp) (const void *a, const void *b)
The insert function...
|
by: maadhuu |
last post by:
hello, this is a piece of code ,which is giving an error.
#include<stdio.h>
int main()
{
int a =10;
void *p = &a;
printf("%d ", *p ); //error....why should it //be an error ?can't the...
|
by: aegis |
last post by:
Given the following:
int a = 10;
int *p;
void *p1;
unsigned char *p2;
p = &a;
|
by: Erik de Castro Lopo |
last post by:
Hi all,
The GNU C compiler allows a void pointer to be incremented and
the behaviour is equivalent to incrementing a char pointer.
Is this legal C99 or is this a GNU C extention?
Thanks in...
|
by: elmar |
last post by:
Hi Clers,
If I look at my ~200000 lines of C code programmed over the past 15
years, there is one annoying thing in this smart language, which
somehow reduces the 'beauty' of the source code...
|
by: junky_fellow |
last post by:
Guys,
Consider a function
func(void **var)
{
/* In function I need to typecast the variable var as (int **)
I mean to say, I need to access var as (int **)
}
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |