Category "pointers"

C : why is that cast of void function to "pointer to function returning pointer to pointer to void" possible

#include <stdio.h> void hello() { printf("hello world\n"); } int main() { void *(*gibberish)() = (void *(*)())hello; (*gibberish)(); voi

How to detect if a block of memory already freed

I already know that there is no way to know if a pointer target still a valid allocation of it's already freed, so I'm trying to use pointer to pointer to solve

Passing and Returning a 2D array of unknown size in C++

I want to pass and return a 2D array of unknown size but I donot know how to do it. I know how to only return array of unknown size only (array of pointers). I

What is cryptic line of code for this statement? [closed]

For example: temp->next = NULL is same as (*temp).next = NULL list->next->next = temp is same as ??

How can I declare a Pointer to a struct in C?

I have learned that pointers can be declared in 3 different ways: int* a; int *b; int * c; I prefer: int* a; While declaring a pointer to a structure, is it c

How to judge whether the incoming buffer is valid in C++?

In my function, a memory pointer and its size are passed as parameters: int myFun(uintptr_t* mem_ptr, int mem_size) { // Code here } Is there any way to te

Invalid conversion from char * to int fpermissive

#include<iostream> #include<vector> using namespace std; int main(int argc,char** argv){ int n; if(argc>1) n=argv[0]; int* stuff=new int[n];

My pointer does not point on the same value when its call in a slot QT C++

I do a pokemon project with a Qt interface. I created a class Trainer and Pokemon : class Pokemon { protected: string itsName; doub

why is the output 1 in this case and when i am doing t-p then its giving me -1

As you can see it is giving me 1 but why? When i do t-p then it gives me -1 . Why ? int f=4, o=8; int *p, *t; p = &f; t = &o; printf("Difference betwee

How can I achieve something similar to a pointer to a string in javascript?

Is there a concept like a pointer to a string in javascript? Or how would this be done? let s1 = "hi"; let s2 = "bye"; // I want to write my code like this [,]

How can I create a 2D array of chars with POINTERS in C?

I'm trying to create a program which the user inputs the number of items (rows) and give each one of them a name (scanf) with the max of 30 characters. I want t

C Pointer Arithmetic for Unusual Architectures

I'm trying to get a better understanding of the C standard. In particular I am interested in how pointer arithmetic might work in an implementation for an unusu

Setting a pointer to a specific array and/or struct element

Here is the scenario: I have an array, AllElements of structure ElementSet, and inside of that structure - is a set of myElement structures and also an array of

How to save/load values from board to file

Im using c++ 11, I need to save/load array to and from file. Its the battleship game its need to be done for both user and computer array but i have no idea how

C++ Read txt and put each line into Dynamic Array

I am trying to read input.txt file, and trying to put each line into the array as string (later on I will use each element of array in initializing obj that's w

Why is "std::is_pointer<std::nullptr_t>::value" equal to false?

I read about std::is_pointer in C++. Then I wrote the program and check whether T is a pointer type or not using std::is_pointer. #include <iostream> i

Copying a certain number of characters from one pointer to another

I have a source pointer (pSource) and a goal pointer (pGoal). I also have a number of characters (n) that need to be copied to the pGoal from pSource. I thought

I try to use placement new, but always complies error

#include <iostream> #include <new> const int BUF = 512; const int N = 5; char buffer[BUF]; int main(){ using n

How to correctly assign a pointer returned by dlsym into a variable of function pointer type?

I am trying to use dlopen() and dlsym() in my code and compile it with gcc. Here is the first file. /* main.c */ #include <dlfcn.h> int main() { v

Why does new int() work like an array in C++?

As far as I understand int* p = new int(); Is something like creating an int with a constructor. If so why does the following code work like an array? int* p =