Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys.

This is my question: Create a function that takes a pointer to pointer to pointer to pointer to pointer to pointer to pointer to pointer to pointer to int as a parameter and sets the value 42 to that int.

What I have tried:

I wrote some, but not sure about it.

#include <stdio.h>

void ft_ultimate_ft(int *********nbr);

int main()
{
    int n;
    int *ptr = &n;
    int **ptr2 = &ptr;
    int ***ptr3 = &ptr2;
    int ****ptr4 = &ptr3;
    int *****ptr5 = &ptr4;
    int ******ptr6 = &ptr5;
    int *******ptr7 = &ptr6;
    int ********ptr8 = &ptr7;
    int *********ptr9 = &ptr8;
    ft_ultimate_ft(ptr9);
    printf("%d\n", n);
}

void ft_ultimate_ft(int *********nbr)
{
    *********nbr = 42;
}
Posted
Updated 12-Jan-23 5:45am
Comments
Rick York 12-Jan-23 11:46am    
Can the code compile? Does it work? It looks to me like it should.
Navid Rigi Ebrahimi 12-Jan-23 14:35pm    
Yeah, it works and shows the number. I thought that would be harder and trickier.

1 solution

And?
If you run that it gives the right result.

So what is to "not be sure" about?
 
Share this answer
 
Comments
Navid Rigi Ebrahimi 12-Jan-23 14:35pm    
It works and shows the result but I wasn't sure about it. I didn't think that to be so easy.
OriginalGriff 12-Jan-23 14:39pm    
Not every task is complicated! :laugh:
Navid Rigi Ebrahimi 12-Jan-23 14:46pm    
Yeah, now I understood that 👍😉😄
Thanks man for your answer 👌
OriginalGriff 12-Jan-23 14:48pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900