I am attempting to read a file with some random names in the format "ADAM","MARK","JESSIE" .....
I have some constraints, the file should be read in a function but should be accessible form the main function with no global variables.
The file size and the no of names in the file are not known.
This is what I have done till now. I have ...
I'm having this problem with C++ classes. I would like to get pointer to myBar object and store it in quxBar. The reason is I would like to be able to check the value using quxBar->getX() but I would also like to prevent from accidentally modyfing it from Qux so I tried using Bar const*.
class Bar
{
private:
int x;
public:
void ...
I understood multi-dimensional arrays as pointers to pointers, but perhaps I am wrong?
For example, I though:
char * var = char var[]
char ** var = char* var[] or char var[][]
char *** var = char var[][][] or char* var[][] or char** var[]
Is this incorrect? I was confused because I saw a char*[][] cast as a char** in a simple...
The code segment given below compiles and when run gives the result as :
$ make
gcc -g -Wall -o test test.c
$ ./test
string
/* code1 */
#include<stdio.h>
char *somefunc1()
{
char *temp="string";
return temp;
}
int main(int argc,char *argv[])
{
puts(somefunc1());
return 0;
}
whereas a slight modification to this code gi...
Hi, I have an array that is passed via a function and assigned to a class member which is a pointer.
class ClassA{
unsigned char * pointerToArray;
ClassA(unsigned char array[]){
pointerToArray = array;
}
~ClassA(){
//what to do here
}
};
Now i have this second class which uses this
class ClassB {
std::list<ClassA> cl...
hi i was studying pointers references and came across different ways to feed in parameters. Can someone explain what each one actually means?
I think the first one is simple, its that x is a copy of the parameter fed in so another variable is created on the stack.
as for the other im clueless.
void doSomething1(int x){
//code
}
voi...
I have a
char** color;
I need to make a copy of the value of
*color;
Because I need to pass *color to a function but the value will be modified and I cannot have the original value to be modified.
How would you do that?
The whole code would look like this
Function1(char** color)
{
Function2(char * color);
return;
}
I have...
Man, pointers continue to give me trouble. I thought I understood the concept.(Basically, that you would use *ptr when you want to manipulate the actual memory saved at the location that ptr points to. You would just use ptr if you would like to move that pointer by doing things such as ptr++ or ptr--.) So, if that is the case, if you...
one of the cpp files has a structure pointer created with "new" operator. Should that pointer be explicitly deleted? Or is the pointer automatically deleted?
...
When I have a class that contains pointers as member variables what type of smart pointer should they have if I want don't want to use plain pointers? They do not need to be shared (so no shared_ptr necessary). scoped_ptr won't work since I often need to build the objects outside of the initialization list.
Or is it maybe common practic...
Is it possible to refer to the address value the pointer variable holds. My function is something(int &num); and I need to pass a pointer to it; int* i = new int(1); like &(*(i)); can this be done?
im using qt and I don't know why but; *&ui->numberInput->text() gives a QString &ui->numberInput->text() gives a *QString, *ui->numberOutput...
Let's say I have this line of code in a program:
int * number=0;
int mystery=&6[number];
Mistery is a number and I can use &5 or &4 obtaining other numbers.
But what does the "&6[]" mean?
Thanks!
...
I am surprised to see this code segment print the same address for all the three pointers.
int main(int argc,char *argv[])
{
int arr[3][3];
printf("%p\n%p\n%p\n",arr,*arr,arr[0]);
return 0;
}
Why this is so ?
...
I am attempting to create a const structure in C but can't seem to figure it out.
typedef struct sA{
char* fname;
char* lname;
} A;
To use as an Array:
A list[] = {{"david","smith"},{"john","smith"}};
However, if I have use a second struct:
typedef struct sB{
A inList[];
} B;
I want to define a const structure as:
B newList...
Trying to understand what the pointer to function actually represent? Is it the address in the code segment where the function resides?
For ex: this piece of code:
#include <stdio.h>
void foo(void)
{
}
int main(void)
{
int a = 10;
printf("a's address: %p\n", &a);
printf("foo's address: %p\n", foo);
return 0;
}
... p...
Hello!
I have some (library API, so I can't change the function prototype) function which is written the following way:
void FreeContext(Context c);
Now, at some moment of my execution I have Context* local_context; variable and this is also not a subject to change.
I wish to use boost::bind with FreeContext function, but I need to ...
I know there's an old saying when you want to indicate this specific pointer doesn't point to anything it should be set to NULL(actually 0), but I'm wondering isn't there actually a physical part of memory with the address of NULL(0) ?
...
I have got some code which uses a lot of pointers pointing to the same address.
Given a equivalent simple example:
int *p = new int(1);
int *q = p;
int *r = q;
delete r; r = NULL; // ok
// delete q; q = NULL; // NOT ok
// delete p; p = NULL; // NOT ok
How to safely delete it without multiple delete?
This is especially difficult if I...
Possible Duplicate:
pointer to a specific fixed address
An interesting discussion about this started here but no one have been able to provide the C++ way of doing:
#include <stdio.h>
int main(void)
{
int* address = (int *)0x604769;
printf("Memory address is: 0x%p\n", address);
*address = 0xdead;
printf("Content o...
How to exclude pointer from boost::ptr_vector without his deletion? =)
...