Questions tagged [null-pointer]

In computing, a null pointer has a value reserved for indicating that the pointer does not refer to a valid object.

In computing, a null pointer has a value reserved for indicating that the pointer does not refer to a valid object.

Use this tag for programming questions that refers to a problems having null-pointer exception, bad memory access etc.

Resources:

365 questions
-2
votes
2 answers

Assigning decimal zero to a C pointer

//line 2 causes the program to terminate #include int main() { int *qi = 0; //1 -- making qi a null pointer if(qi==NULL) printf("Null\n"); else printf("Not Null\n"); *qi =0; // 2 --- assigning *qi a decimal zero value. return…
log0
  • 2,206
  • 2
  • 14
  • 24
-2
votes
2 answers

How to store custom objects in an ArrayList

I'm making a game with cards, characters cards. I first create the cards chosen by the user, then add them to a List, shuffle it and then display 'em one by one, with their players name (chosen in a previous activity by the user). The fact is, when…
FET
  • 942
  • 4
  • 13
  • 35
-2
votes
4 answers

Adding objects to array list

Hello i am trying to add my Class's objects into an ArrayList with the objects attributes but i keep getting null pointers I am reading values from a txt file assigning them to the attributes and then put the object into the array list here is my…
Eilleen
  • 357
  • 1
  • 16
-2
votes
2 answers

How to resolve NullPointerException in multidimentional array?

I want to create a multidimentional array with Fibonacci numbers. I need to create rows with odd numbers. After compiling I receive NullPointerException. Could You help me find solution for this issue? public class Scratchpad01 { public static int…
-2
votes
4 answers

How can I create an array of pointer and points it to NULL using **P?

How can I create an array of pointer using **P and point it to NULL? Let's say I have coded as below . struct s { float a ; char x ; } ; s **p ; p = new ( s * [10] ) ; Now I want to make some of them as NULL p[0] = NULL ; p[5] = NULL…
john
  • 337
  • 2
  • 15
-2
votes
1 answer

Can't return nullpointer in Cpp function

I am not able to return the nullptr at the end of this method? Is there some kind of library I need to import? const char* strstr(const char* string1, const char* string2) { // TODO: for (int i = 0; i < strlen(string1); i++) { for…
letter Q
  • 14,735
  • 33
  • 79
  • 118
-2
votes
1 answer

Runtime error: Null pointer assignment and abnormal termination of program on 16bit ms dos system

class node{ unsigned long int data; node *lchild,*mchild,*rchild; //childs of ternery tree unsigned long int *stack1,*stack2; static int count,top1,top2; public: node() { data=0; lchild->data=0; …
Ranjeet
  • 1
  • 1
-3
votes
4 answers

Determining null pointer

I have function that returns pointer to child object. Function prototype: ObjClass* ObjClass::getChildFromParent(ObjClass* parent = nullptr); This function has default parameter as null pointer and I want to check this parameter anyway, because if…
WideWood
  • 549
  • 5
  • 13
-3
votes
3 answers

Adding integer to null pointer address is returning unexpected result

#include int main() { int *numPtrA = NULL; // pointer to an integer pointer to null.. ascii value of zero printf("%p\n", numPtrA + 2); // prints 0x8 which i expect printf("%p\n", numPtrA + 5); // prints 0x14 and i dont…
Hamza Kyamanywa
  • 417
  • 3
  • 8
-3
votes
1 answer

What happens when malloc doesn't find the memory?

What happens when malloc returns the NULL value to the pointer? When this if statement gets executed if (ptr == NULL) { printf("Memory not allocated.\n"); exit(0); } And we come out of the program. Then after that what makes malloc…
-3
votes
5 answers

Can anyone explain to me what actually causes this Segmentation Fault and How to overcome this?

#include #define null1 ((void*)0) #define val ((int)2) int main() { int *p; p = null1; printf("%p", &p); //p = (int *)val; *p = val; //printf("\n%p", (int*)p); return 0; } Output: Segmentation fault(core…
eddyctid
  • 11
  • 1
-3
votes
3 answers

In this function is defective since dereferencing null is not valid so i want to change code

long cread(long *xp) { return (xp? *xp : 0); } It is invalid since it could attempt to read from a null address So the solution suggested this code long cread_alt(long *xp){ long tem = 0; if(*xp > 0){ tem = *xp; } return tem; But I…
user10430594
-3
votes
2 answers

Why my head pointer is changing in linked list,even not passing it by reference?

I created a linked list, and made a function reverseList which takes a pointer to head and return pointer to last node. Node* reverseList(Node *head) { Node* curr=head; Node* prev=NULL; Node* ahead; while(curr!=NULL) { …
Suhail Akhtar
  • 630
  • 7
  • 18
-3
votes
1 answer

Will any of these crash my program?

I've received a task in my university, which is to write a smart pointer. I need to upload the code to their server which runs some automated tests on it, and I've got only one error: memory access problem (null pointer or the like). Now I'am…
masm64
  • 1,222
  • 3
  • 14
  • 31
-3
votes
1 answer

implementing the bubble sort using linked_list. Null pointer exception

I'm trying to implement bubble sort using linked list and here is my code: itr = head; for (int j = 1; j < size; j++) { for (int k = 0; k < size - 1; k++) { if (itr.item >…
user3037348
1 2 3
24
25