0

Why does it always skips this if statement?

https://code.sololearn.com/c30YU02VI6KP/?ref=app

8th Oct 2018, 2:23 PM
Oleg Storm
Oleg Storm - avatar
8 Réponses
+ 1
don't know much about cpp so I don't know if you have changed 'n' to 1 but as long as n = 0 it will also be the same as false such as 1 is equal to true in if statements
8th Oct 2018, 2:28 PM
Roel
Roel - avatar
+ 1
at the first run n is nullptr, as far as i know it'll be treated as false in if statement
8th Oct 2018, 2:36 PM
Taste
Taste - avatar
+ 1
You have to pass a pointer to edit a var from inside a function... Then if you have to edit an int, you have to pass an int*. If you have to edit an int* you have to pass an int** ... Try to see this code https://code.sololearn.com/cng46f40L7ne/?ref=app
8th Oct 2018, 5:40 PM
KrOW
KrOW - avatar
0
if you want the if loop to be done if n = 0 you could do if(n==0) or if(!n)
8th Oct 2018, 2:29 PM
Roel
Roel - avatar
0
if n is a null pointer (nullptr or NULL) then n will be valutated false as boolean
8th Oct 2018, 2:31 PM
KrOW
KrOW - avatar
0
Krow, but it's always nullptr, i don't know why
8th Oct 2018, 2:39 PM
Oleg Storm
Oleg Storm - avatar
0
Oleg Storm Its normal that its always nullptr because the "if" block never run and though if it would run, you have to modify "n" insided main from the function (with pointer to pointer or reference)
8th Oct 2018, 2:41 PM
KrOW
KrOW - avatar
0
Krow, like if i create a new Node, this node will point to NULL?
8th Oct 2018, 4:19 PM
Oleg Storm
Oleg Storm - avatar