Skip to main content
Filter by
Sorted by
Tagged with
10 votes
1 answer
741 views

Consider the following program: int main() { int* ptr = nullptr; return *ptr + 1; } (also on GodBolt) How is it, that with "decent" warnings enabled (-Wall -Wextra), both popular ...
einpoklum's user avatar
  • 137k
3 votes
1 answer
105 views

I have implemented begin and end functions for MFC containers. The iterators are pointers to the internal data and may be null pointers for an empty container. What happens if both are null pointers ...
Martin Fehrs's user avatar
  • 1,175
2 votes
1 answer
154 views

So in risc-v, for a virtual memory system, I imagine it's up to the kernel to decide if 0 is a valid memory address or not? But for machine mode, or supervisor mode, is memory address 0 valid to ...
CocytusDEDI's user avatar
5 votes
2 answers
195 views

It seems unclear, but there are claims that dereferencing a nullpointer is undefined behavior: A comment by M.M. This note was in fact removed as the result of DR 1102 with the stated reasoning being ...
lucidbrot's user avatar
  • 6,552
0 votes
1 answer
126 views

This is some of the strangest behavior I've ever seen and I have no answer from myself. I tried -fno-delete-null-pointer-checks while compiling both my game and engine and still the same behavior was ...
Aidan's user avatar
  • 87
1 vote
2 answers
167 views

I'm reading the C document n3042 Introduce the nullptr constant and when it enumerates the properties of nullptr there is the following: In memory, nullptr is represented with the same bit-pattern as ...
xdevel2000's user avatar
  • 21.6k
0 votes
1 answer
95 views

I am currently learning pointers in c. I have learned that if I do not assign an address to a pointer and try to print the value of the content of the pointer, then the program will not run properly. #...
Akib Aftermath's user avatar
7 votes
2 answers
207 views

The expresssion (void *)0 is called a null pointer. But how about the following: int i = 0; void *s = (void *)i; Is s also a null-pointer? The C-language standard says: 6.3.2.3 Pointers 3 An integer ...
wimalopaan's user avatar
  • 5,552
0 votes
2 answers
137 views

The following code does contain UB. The gcc docu says, that the compiler can assume a pointer is non-null after it has been dereferenced. So option <1> and <2> should lead to the same ...
wimalopaan's user avatar
  • 5,552
0 votes
0 answers
46 views

Im reading information from a CSV file and im getting random symbols at the start of my first input, my understanding is that compiler doesn't know where the start of the string is so looks for the ...
displayname's user avatar
0 votes
1 answer
61 views

I want to tokenize a provided input string using strtok(). In the first step, I want to tokenize the given string by "|" symbol. Then, I tokenize each substring by ";". Finally, I ...
Devon's user avatar
  • 1
38 votes
2 answers
3k views

Latest gcc 13.x (trunk) gives a compiler error (gcc -std=c23) for this code: int* p = false; error: incompatible types when initializing type 'int *' using type '_Bool' How can this be correct? C23 ...
Lundin's user avatar
  • 220k
2 votes
1 answer
119 views

Is it guaranteed by the C standard that, given type_t* x = NULL; type_t* y = NULL; we always have x > y evaluating as false? I ask because of the conversation in initial or terminal malloc buffer ...
Sasha's user avatar
  • 371
5 votes
2 answers
670 views

Several compiler vendors have implemented a non standard extension __attribute__((nonnull)) to specify that a pointer must not be a null pointer. C99 introduced a new syntax to specify that a function ...
chqrlie's user avatar
  • 152k
-1 votes
1 answer
379 views

I am a learning file handling in C. I tried implementing a program but no matter what I do the file pointer is still null. I checked the spelling, the directory, even tried adding and removing .txt ...
Rupa TS's user avatar
  • 19
1 vote
1 answer
61 views

I have a struct named Row : typedef struct { uint32_t id; char username[COLUMN_USERNAME_SIZE]; char email[COLUMN_EMAIL_SIZE]; } Row; Also, I have defined a Macro : #define ...
hashim's user avatar
  • 55
-2 votes
1 answer
54 views

So i am trying to solve a problem to reverse a linked list and following is what i came up with. class Solution { public: /* void insertList(struct Node* head, int data) { Node* temp{ ...
electric fan's user avatar
2 votes
0 answers
115 views

https://source.android.com/docs/core/tests/debug/native-crash says: "You can reproduce an instance of this type of crash using crasher strlen-NULL." How to do that actually? Open a "adb ...
René Heuven's user avatar
18 votes
6 answers
5k views

From the C17 draft (6.3.2.3 ¶3): An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.67) If a null pointer constant is ...
Lover of Structure's user avatar
2 votes
1 answer
47 views

I am attempting to create a DVR simulation in C. I know that I need a nested for loop, but whenever I compile and run the program it produces a segmentation fault after entering the number of routers ...
TrinityCoding's user avatar
-1 votes
3 answers
115 views

I am getting these results. What am I doing wrong? const char *c = "\0"; cout << (c == NULL); // false cout << (c == nullptr); //false
leeway00's user avatar
  • 189
1 vote
1 answer
60 views

My console says Math: 5.0 false English: 3.0 true Physics: null false Chemistry: null false This sound ok, but in my Code I had a Exception-Code. I do not understand why I get null here: Physics: ...
Emirhan Hans's user avatar
4 votes
0 answers
50 views

I’m quite sure this question has been asked before, but I just couldn’t find it. If I have a pointer that is null, e.g. a char* initialized to nullptr, is it undefined behavior (UB) to add 0 to it? I ...
Bolpat's user avatar
  • 1,775
0 votes
1 answer
391 views

I'm playing around with a linked list, and I'm getting an error when I try to print out the value of the tail and the address of the next value: struct Node { int n; Node *next; }; class ...
asvalk1672's user avatar
2 votes
3 answers
541 views

I had hoped for a short, concise, elegant: std::array<int*,10> ip_arr; bool all_null = std::all_of(ip_arr.begin(),ip_arr.end(),std::is_null_ptr_as_fn); instead of inventing a lambda for that ...
Vroomfondel's user avatar
  • 2,928
0 votes
1 answer
126 views

Any of my C programmes utilizing fopen() run perfectly from IDE or Windows environment, but fail when opened from Command Line (cmd.exe), as fopen("r") keeps returning NULL pointer. The ...
Martin Andy's user avatar
0 votes
1 answer
449 views

This is my method. public boolean authenticateAndPollCallbackResult(BankIdAuthRequest bankIdAuthRequest) { ResponseEntity<BankIdAuthResponse> authResponse = bankIdAuthentication(...
Mr.Gomer's user avatar
  • 631
0 votes
1 answer
2k views

I found one more case when compiler thinks that static_cast may return nullptr on non-nullptr argument. It seems that this time there is no undefined behavior, like was before, but maybe I'm missing ...
αλεχολυτ's user avatar
0 votes
0 answers
274 views

The following code gives me a warning "null pointer dereference" despite checking the pointer value before casting: struct ID { virtual ~ID() = default; }; struct IF { virtual void g() = 0; }...
αλεχολυτ's user avatar
70 votes
9 answers
9k views

According to §6.3.2.3 ¶3 of the C11 standard, a null pointer constant in C can be defined by an implementation as either the integer constant expression 0 or such an expression cast to void *. In C ...
Brad Jones's user avatar
-1 votes
2 answers
287 views

i want to know that why we use two conditions i am confused.. while head and head->next are not equal to null which means head and head's next will point to null ho is that possible int detectCycle(...
Athar Mujtaba Wani's user avatar
1 vote
1 answer
64 views

I am fairly new to C and wanted to create a linked list. For the list-elements I created a structure and wanted to initialize the head element in a function. The last element of the list shall contain ...
GandalfGreybeard's user avatar
5 votes
2 answers
547 views

Are there any ANSI C conforming environments where all-bits-zero is not a representation for a null pointer? That is, environments where the following program would print 0? If so, can you list some ...
math4tots's user avatar
  • 8,909
0 votes
0 answers
144 views

I've given up here and I'm starting over with a clean new question 😭 Let me try to rephrase the question as objectively and simply as possible: I want someone to either give me a list of platforms (...
math4tots's user avatar
  • 8,909
0 votes
1 answer
161 views

I am currently working on a program and have run into a runtime error, ironically I cannot seem ti find the source of it at all, I have tried playing around with the char[] size, but since the problem'...
huntrese's user avatar
0 votes
2 answers
77 views

I'm trying to create a Ceasar Cipher. For this test, I used a key of 1 and plain text of "hello." When doing so, I get the error message "Segmentation fault (core dumped)". I know ...
Ryan's user avatar
  • 3
5 votes
2 answers
715 views

I am debugging a crash where we have a code snippet similar to - 1184 static void 1185 xyz_delete (<struct type1> *c, <struct type2> **a) 1186 { ... ... ... ... 1196 b = *a; 1197 if (...
Naman Sharma's user avatar
0 votes
1 answer
106 views

I tried to work with the points but nothing I do seem to work. Essentially this will be run in main and a number n is inserted to find all the prime numbers from 0 to n. This is then written into a ...
Vicgi's user avatar
  • 1
-1 votes
4 answers
1k views

I have a char array and I want to check if it is null. if(_char_array[0] != '\0') {...} is the same as if(_char_array != '\0') {...} thanks
KostasA's user avatar
  • 5,688
1 vote
3 answers
461 views

I was trying to learn the Linked list and perform insertion operations from beginning of the list. while printing the nodes, the first node is not printed. Here is the core functions which I have ...
Prajapati Dhruv's user avatar
3 votes
0 answers
261 views

Fatal Exception: java.lang.NullPointerException Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res....
Gaurav Singh's user avatar
1 vote
0 answers
102 views

I'm implementing std::vector-like class. Its iterators are just plain pointers. The problem is that if the vector is empty (there is no allocated buffer for elements) it returns nullptr as begin and ...
anton_rh's user avatar
  • 9,462
8 votes
2 answers
2k views

I'm trying to learn Fortran2018 using gfortran. When playing around with pointers I noticed that there doesn't seem to be a facility to test for nullpointers. So I have two questions: Is there really ...
Codebird's user avatar
  • 121
1 vote
1 answer
124 views

i found the linked code and found this for loop which is a bit strange for me. i would appreciate if someone could explain me the syntax of this loop to me. MFG void patch(Ptrlist *l, State *s) { ...
user19007709's user avatar
0 votes
0 answers
95 views

Similar question here . What I want to understand is that when current_node is NULL, the compiler doesn't see it as NULL and iterates one more time. void printBranches(struct bank *head) { ...
Mahmut Salman's user avatar
2 votes
1 answer
73 views

I'm trying to create a BST, add a node, and print the data in that node, but I keep getting invalid memory address or nil pointer dereference errors. I know something is wrong with my pointers, and I'...
Victor's user avatar
  • 75
1 vote
1 answer
116 views

In this code: Pointer_pu32 points to variable a, but which is pointer Boot_st point to? int * Boot_st; int a = 15; int * Pointer_pu32 = &a; Boot_st = (int *)(*Pointer_pu32); /* what was this ...
MAK1647's user avatar
  • 11
34 votes
3 answers
3k views

In some legacy code I came across the following null pointer check. if( myPtr > 0 ) { ... } Are there any technical risks of checking for a null pointer via this if-check?
ucczs's user avatar
  • 663
0 votes
0 answers
16 views

I keep getting NullPointerException on all my Tests. I have a CashRegister Class with a Product object lastScannedProduct that is supposed to be initially null but then it's supposed to be changed I ...
Ondra Hrubý's user avatar
1 vote
3 answers
303 views

C2x, 6.5.3.2 Address and indirection operators, Semantics, 3: The unary & operator yields the address of its operand. A simple question: can the unary & operator yield the address 0 (null ...
pmor's user avatar
  • 6,757

1
2 3 4 5
8