Questions tagged [pointers]

Data types for "pointing" at other values: A pointer's value is a memory address where the pointed-to value is stored. This tag should be used for questions involving the use of pointers, not references. Common programming languages using pointers are C, C++, Go, and assembly and intermediate-representation languages; use a specific language tag. Other helpful tags should describe what is being pointed-to (e.g. a function, a struct etc.)

pointers
Filter by
Sorted by
Tagged with
1 vote
1 answer
2k views

Unable to pass two dimensional array using double pointer as function argument [duplicate]

I am trying to pass a 2D-array to a function using double pointer,however the compiler is giving the following error [Error] cannot convert 'int (*)[3]' to 'int**' for argument '1' to 'void print1(...
user3262269's user avatar
1 vote
4 answers
207 views

Multidimensional array on the heap - C

I am learning C and trying to make a function that would create an array of arrays of strings. #include <stdio.h> #include <stdlib.h> #include <string.h> void parse(char ***aoa) { ...
Alex Smirnov's user avatar
1 vote
2 answers
2k views

C++ Object doesn't save value

Objects I created for the Player class does not change the private variable even tho it does in the function that changes it. There maybe some reference problems with the objects being used in the ...
youngin123's user avatar
1 vote
2 answers
732 views

Erase element from list of type struct

This is the declaration of my list: list<Message*> g_messages; where Message is a struct. I want to delete a certain position of the list (a Message). If it was a vector, I would do it like ...
Ane's user avatar
  • 43
1 vote
3 answers
192 views

C++ Stacked List push function printing next/previous element

I just had a question on printing out the previous value. The code prints out everything fine for when it pushes on top of the stack but when I try to output what was the previous head it just points ...
user2444400's user avatar
1 vote
3 answers
823 views

How to access pointer to 2-d array in c struct?

I am having trouble with following struct for using it as Matrix struct{ int col; int row; int (*p)[col];//In this line compiler is giving error, saying col undeclared ...
OldSchool's user avatar
  • 2,143
1 vote
2 answers
546 views

Use pointer arithmetic to change the value of a variable in another function.

#include <stdio.h> void interrupt(); int main() { int n = 8; char c = 'Z'; interrupt(); printf("%d%c\n", n, c); } void interrupt() { printf("Run normally\n"); //ADD CODE... } As it ...
Senescence's user avatar
1 vote
1 answer
19k views

Using a while loop to iterate through a char array received as a parameter in C

I'm still a little new to C, and one hiccup I've been stuck on for the past bit is iterating through a char array received as a parameter. The char array was created as a String literal and passed as ...
Dene Wong's user avatar
1 vote
4 answers
2k views

Invalid Pointer?

I recently learned about pointers, and have been working hard to really understand them. However, I have run into trouble. For class we had to write a function that would double an array x amount of ...
Σqu's user avatar
  • 47
1 vote
3 answers
420 views

What exactly int/char when we declare double pointer(**q)

Lets take 64 bit machine where pointer is of 8 bytes in 64 bit machine int *p ; // it is a pointer to integer variable so when i increment p // i.e., p++ it will increment by 4 char *r; /...
Vivek 's user avatar
  • 181
1 vote
4 answers
227 views

Trying to set up a class thru .h and .cpp files -- why do I get these errors?

I'm using g++ on Debian 8.2 Jessie. I'm learning about classes in C++. I think I understand the basics, but not fully how to instantiate class objects with header files. Here's Movie.h: #ifndef ...
Username's user avatar
  • 3,553
1 vote
3 answers
2k views

Why can I call a non-static function by a static pointer?

I thought I cannot use a static pointer to call a non-static function, since I think a static pointer belongs to the whole class but non-static function belongs to a specific object. But somehow I ...
gladys0313's user avatar
  • 2,619
1 vote
3 answers
65 views

Checking array for identical numbers and their value

As part of a program that I have to make, one of the function that I need to program should check if the array has any identical numbers that are the same, and if one of them is bigger/equals to a ...
Voxito's user avatar
  • 33
1 vote
2 answers
87 views

Error initializing a vector with local objects

I want to create a vector with diferent object of type A but ... This code throws this exception: free(): invalid pointer: 0x0000000000401757 *** #include <vector> class A { char * ...
GutiMac's user avatar
  • 2,432
1 vote
1 answer
70 views

Unable to create a reference to a new instance of a class

I'm new to C++ and is trying to learn the concept of pointer and references. I tried to create a reference and a pointer to a new instance of a class using the statement below Animal *rA = new Animal(...
Thor's user avatar
  • 9,888
1 vote
1 answer
887 views

How does cv::Ptr<CvHaarClassifierCascade> be released?

Assuming: CvHaarClassifierCascade* pCascade; cv::Ptr < CvHaarClassifierCascade > ptrCascade; Assuming the xml file has been loaded in both pCascade and ptrCascade. Now we try to release them. ...
DarkDreamer's user avatar
1 vote
1 answer
328 views

How offset of structure is calculated? Explain printf statement here?

#include<stdio.h> main() { unsigned char c; typedef struct name { long a; int b; long c; }r; r re = {3,4,5}; ...
Punit Vara's user avatar
  • 3,949
1 vote
3 answers
406 views

Pointer-to-Member invalid conversion from ‘Derived X::*’ to ‘Base X::*’

I wonder why a simple conversion from a derived class pointer to the base class pointer fails in the case of the pointer-to-member conversion. For example, struct Base {}; struct Derived: ...
Andrei Kouznetsov's user avatar
1 vote
3 answers
5k views

c++ - declaration is incompatible with (method) - pointers

I recently started playing around with c++, but for I don't understand what this means: I get this error: declaration is incompatible with "void student_system::addStudent(<error-type> z)" ...
CybeX's user avatar
  • 2,308
1 vote
1 answer
167 views

Delete a pointer c++

I have a c++ program that in a part of it the size of pointer is increased if user enters more elements. This pointer has a type associated with structure Entry and the function that increases the ...
Amin's user avatar
  • 261
1 vote
3 answers
131 views

Passing a pointer to one derived class to another

I'm still learning basics of c++, but I'm currently working on a project using derived classes and virtual methods. So the situation is: I have a ClassA class ClassA { public: virtual void action(...
nabacc001's user avatar
1 vote
3 answers
3k views

Why struct I pass does not change

I am passing a struct to a function by reference. I was expecting if I define and change the struct inside the function I can get the new value outside. But it is not happening. Can anyone explain ...
Ikomi Kara's user avatar
1 vote
1 answer
69 views

Is this piece of code technically valid?

int *b = arr, *e = arr + sz; // sz has a type of size_t while (b < e) { // use *b ++b; } This is the code on C++ Primer. I'm quite new at C++, may I know what if sz is very large so an int can'...
hiimgosu's user avatar
1 vote
2 answers
89 views

How to remove top-level pointer from typename?

For example if I have: typedef int (*pFuncType)(int a, char b); And I want for ease to declare a function of the type which 'pFuncType' is pointer to. Something like this: (*pFuncType) funcDeclr; ...
AnArrayOfFunctions's user avatar
1 vote
2 answers
294 views

Use a pointer to a char array to get the length of the string to copy using strstr()

I want to copy a part of a phrase to a char array, and then a second part of the same phrase to another one. I'm trying to use strstr and then strcpy, but I'm not sure I'm using the pointer in the ...
Ghislo's user avatar
  • 85
1 vote
2 answers
71 views

how to add String by value and not reference

Im making a really simple TODOlist in C. My add function takes a char * as its parameter. When I add it to my char ** list of reminders, it adds the memory address of my buffer instead of the value ...
Kevin Price's user avatar
1 vote
1 answer
76 views

Read from .txt File and store specific lines in strings

I have a text document looking like this: #Something info1 #Something info2 #Something info3 Now I want to read this file and skip all lines starting with # and store the normal strings in a char ...
N.W.A's user avatar
  • 75
1 vote
2 answers
147 views

Why don't the two pointer values be the same?

Quoting Effective C++, Scott Meyer, 3rd Edition , Item 27 class Base { ... }; class Derived: public Base { ... }; Derived d; Base *pb = &d; // implicitly convert Derived* ⇒ Base* Here we’re ...
Sreeraj Chundayil's user avatar
1 vote
1 answer
1k views

How can I pass a C++ array of structs to a CUDA device?

I've spent 2 days trying to figure this out and getting nowhere. Say I had a struct that looks like this: struct Thing { bool is_solid; double matrix[9]; } I want to create an array of that ...
Yousef Amar's user avatar
1 vote
5 answers
391 views

Returning base address in C(Pointers)

I am learning pointers and i tried this following program #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; char* getword() { char*temp=(char*)malloc(...
user5685026's user avatar
1 vote
3 answers
115 views

How to define a getter function

I'm writing a library which allows to build Bayesian nets. The structure of a net is encapsulated and the user cannot access its fields; however they can get and set some of them. Say you want to ...
nicola's user avatar
  • 24.3k
1 vote
1 answer
1k views

Casting to pointer from integer of different size

I'm using Atmel Studio to build hex files for AVR microcontrollers. Every time I try to build a certain project while using the following function is generating a warning of casting to pointer from ...
Mina Emil's user avatar
1 vote
3 answers
56 views

Difference between : list<object *> and list<object &>

if i have a class "Movie" as follows:(c++) class Movie{ private: string name; string year; list<Employee ?> e; } what is the difference between : list<Employee *> e ...
Mahmod's user avatar
  • 23
1 vote
1 answer
607 views

Array of Pointers in C++

I'm trying to writing some code for my c++ class. I'm using eclipse. I'm having a hard time trying to understand some of the instructions in the problem. I've created a base class called Ship and ...
redcardinal's user avatar
1 vote
2 answers
119 views

(NASM, C)Why would you need to malloc twice to create an array as shown here

char** names=(char**)malloc(count*sizeof(char*)); //while loop names[count]=(char*)malloc(size+1);//why malloc again? So char** names=(char**)malloc(count*sizeof(char*)); creates a pointer to a ...
haris's user avatar
  • 149
1 vote
3 answers
70 views

one address have two values?

The following code shows me that for one address I have two values. For an example: Address is: 0xbfcca1ac <br> Value is: 5 Address is: 0xbfcca1ac <br> Value is: -1077108308 What am i ...
Filip6220's user avatar
1 vote
4 answers
2k views

If I copy a pointer and then free it, does the original data disappear?

I'm trying to create a linked list in C, and I'm wondering what will happen to cursor once I free it. cursor points to the same struct that head does, so when I free cursor will it also free ...
Kyler Brown's user avatar
1 vote
1 answer
174 views

Right button in Listwidget

I have a method to delete the list of files on the QListWidget: void MainWindow::ProvideContextMenu(const QPoint &pos) { QPoint item = ui->listWidget->mapToGlobal(pos); QMenu ...
user5603723's user avatar
1 vote
2 answers
504 views

From argv to execvp

So I have a problem I haven't been able to solve. I'm writing a C program that executes some OS functions via pipes. The execution is done with execvp(const char *file, char *const argv[]);. In my ...
Gabriel Tigerström's user avatar
1 vote
3 answers
5k views

MISRA C++-2008 Rule 5-0-15 - Array indexing shall be the only form of pointer arithmetic

I need someone who has more experience with MISRA to help me to solve this. I have the following code: byte* buf = new(std::nothrow) byte[bufferSize]; ..... for (uint32_t i = 0; i < bufferSize; i+...
Baj Mile's user avatar
  • 760
1 vote
1 answer
586 views

How can pointer to a type be treated as a pointer to an array of that type

So according to this (applies to the same page for XE4 to XE8): When a pointer holds the address of another variable, we say that it points to the location of that variable in memory or to the data ...
Raith's user avatar
  • 871
1 vote
1 answer
2k views

Escaping characters in C

I want to replace all special characters in a string with their escaped equivalences (\n \t \\ \"). My idea is to use reader and writer and then put \\ before any special character. I use an dynamic ...
Dimitar's user avatar
  • 4,561
1 vote
4 answers
939 views

copy string to char**

I do not understand why the following code: char** receive_message(char** ret) { char* temp = "text"; strcpy(&ret, temp); return ret; } gives this error: warning: passing argument ...
Mari's user avatar
  • 35
1 vote
2 answers
3k views

C++: Change value of variable using its pointer

Let's say I have the following funciton: void part(T* arr){ //some function int x[5] = {1,2,3,4,5}; arr = x; } where original: int arr[5] = {0,0,0,0,0} I would like to know, how can I change the ...
uksz's user avatar
  • 18.5k
1 vote
2 answers
223 views

Strange double free behavior

Below I have a function trim(). Which removes the leading zeros from an array of ints. It returns a pointer, which it receives from malloc(). While running a loop of successive calls to trim() and ...
hermetik's user avatar
  • 115
1 vote
1 answer
506 views

Calling a procedure by pointer from variable in Intel 8086 Assembly

Let's say I have a variable with procedure address: func_pointer dw offset my_function my_function proc near my_function endp How can I call it from the variable? I have tried call dword ptr[...
Haris Vitunskas's user avatar
1 vote
3 answers
7k views

C Compare array elements using pointers

I'm trying to make a program to compare array elements using pointers and to give me some result; I make this simple program just to test if it works but I don't know why.. if i enter equals numbers ...
Ciprian Ambrus's user avatar
1 vote
1 answer
77 views

C - values in array overriden after leaving while loop

I have some strings I add into an array in a while loop. Everything is good and seems added inside the while loop, but when I leave the while loop and loop through the array to inspect the values, the ...
Kingamere's user avatar
  • 9,846
1 vote
2 answers
73 views

C String cropping runtime error

I want to have a function that returns me k-th word from string str. char* word_at(int k, char* str) { char *p; for (p = str; *p != '.'; p++) { if (k == 0) { ...
YTerle's user avatar
  • 2,636
1 vote
1 answer
237 views

Unexpected "random" characters when writing file

While running this section, my .dat file gets some random characters. I don't get it, what am I doing wrong? fstream file("trial1.dat", ios::app | ios::in | ios::out); file.seekg(0, ios::end); login ...
Aditya Petety's user avatar

1
380 381
382
383 384
1134