Davi
I had only int(8 bit) on my 1$ avr cpu. maybe this compiler does not satisfy standard
The standard mandates the presence of the definition of the least types for 8, 16, 32 and 64 bits, but it also says that if there is no support due to architectural implementations, there should be no unsupported macros on stdint.h: "Conversely, for each type described herein that the implementation does not provide, <stdint.h> shall not declare that typedef name nor shall it define the associated macros. An implementation shall provide those types described as “required”, but need not provide any of the others (described as “optional”)." Maybe C2X will solve this oddity.
Alex
thank you
Jaaa
When to use void and. When to return can anyone explain other than that boring definition
Jaaa
When to pick apples and when oranges
Well this is not a part of my questions i wanna know. how to use them accordingly
Vlad
Well this is not a part of my questions i wanna know. how to use them accordingly
Well if you code a logarithm function you'd wanna return a value
Vlad
It's about semantics
Vlad
Well if you code a logarithm function you'd wanna return a value
If it is some subroutine and you don't care about the result it returns(imperative programming) then you declare it void
Davi
When to use void and. When to return can anyone explain other than that boring definition
If your function informs a status code, tradition says that the return code should be returned as an int, although you are free to use pointers in the function parameters and accomplish the same objective with a function declared as void.
Vlad
Or you do in the way that printf/scanf does
Vlad
Which is amount of successful operations
Jaaa
What is the difference between String subseq(string s) { String ans= s.substr(1); Subseq(ans) } And String subseq(string s) { String ans= subseq(s.substr(1));
λ⃗
/get cbook
λ⃗
/get cppbookguide
λ⃗
/get ide
λ⃗
/get ide
Prajal
/get
Prajal
/get ide
Davi
How would you hope C2X to change this? E.g. you can't implement a uint12_t on your x86 hardware, but can implement the least and fast versions of it.
Oh, I think I expressed myself poorly. I intended to say that I hoped that C2X stated more clearly that the fixed width integer types in powers of two are optional, as the current version implies that only the arbitrary widths are optional.
Sunil
/get
Saurav
/get ide
Fitrat
Unmute me
Xudoyberdi
Fitrat
Okay.
Thanks
Anonymous
https://nekobin.com/miqilazozi I'm doing Single linked list implementation with its operations in C. In the void insert() function in case 2 of the switch statement, where I insert a node anywhere in between the first and last node, but something is wrong, when i run the program, and execute the case 2 of insert function , the program gets stuck and it doesnt go beyond that and forcefully exits the program.. OUTPUT: 1.Create 2.Display 3.Insert 4.Find 5.Delete 6.Exit Enter your Choice : 1 Enter the no.of nodes to be inserted : 4 Enter the Value : 1 Enter the Value : 2 Enter the Value : 3 Enter the Value : 4 1.Create 2.Display 3.Insert 4.Find 5.Delete 6.Exit Enter your Choice : 2 1--->2--->3--->4---> 1.Create 2.Display 3.Insert 4.Find 5.Delete 6.Exit Enter your Choice : 3 1.Beginning 2.Middle 3.End Enter your Choice : 2 Enter the Value : 56 1--->2--->3--->4---> Enter the position to insert the Node : 3 U:\DSA Practice> I couldn't move forward cuz, it doesnt show any error at all....
Anonymous
Write a program to store student assessment marks in 2D array. Total assessments are 2, we need to store student reg no, 2 assessments (with obtained and total marks) and total obtained of these assessments
Anonymous
can any one solve this
Xudoyberdi
can any one solve this
Try yourself first. Not complicated.
Xudoyberdi
If you face errors, Pros here will help.
Anonymous
i need solution please anyone solve me this
Anonymous
Xudoyberdi
i tried but not do it
Show what you have tried.
Anonymous
#include<iostream> using namespace std; int main(){ int arr[10][8],x,y,z=-1; for(int i=0;i<10;i++){ x=0; cout<<"Enter student roll No :..\n"; cin>>arr[i][x]; x++; cout<<"Enter student assesment 1 total marks :..\n"; cin>>arr[i][x]; x++; cout<<"Enter student assesment 1 obtained marks :..\n"; cin>>arr[i][x]; x++; cout<<"Enter student assesment 2 total marks :..\n"; cin>>arr[i][x]; x++; cout<<"Enter student assesment 2 obtained marks :..\n"; cin>>arr[i][x]; x++; arr[i][x]=arr[i][x-4]+arr[i][x-2]; x++; arr[i][x]=arr[i][x-4]+arr[i][x-2]; x++; arr[i][x]=(arr[i][x-1]*100)/arr[i][x-2]; } cout<<"Enter student roll No :..\n"; cin>>y; for(int i=0;i<10;i++){ if(arr[i][0]==y){ z=i; break; } else{ cout<<"Assesment 1 :"<<arr[z][2]<<"/"<<arr[z][1]<<"\n"; cout<<"Assesment 1 :"<<arr[z][4]<<"/"<<arr[z][3]<<"\n"; cout<<"Total:.."<<arr[z][6]<<"/"<<arr[z][5]<<"("<<arr[z][7]<<"%)"; } } return 0; }
Anonymous
its not working accurately
olli
tnx! , but if I put head as a local in void create() how to pass it to other fucntions??
good point, for head, you could leave it global and just change the other two. Another option would be to change the functions so they accept the head of the list as a parameter so your program can deal with multiple lists and don't rely on head being the same all the time. e.g. void create(N **list){ N *newNode; int i,n; scanf("%d",&n); for (i=1; i<=n; i++){ newNode = malloc(sizeof(N)); scanf("%d",&newNode->val); newNode->next = NULL; if (i==1){ *list = newNode; temp = *list; } else{ temp->next = newNode; temp = newNode; } } } void display(N * list){ N * temp = list; while (temp!=NULL){ printf("%d--->",temp->val); temp = temp->next; } } and in main you could do instead int main() { N *List1 = NULL; // ... do{ scanf("%d",&choose); switch (choose){ case 1: create(&List1); break; case 2: display(List1); break; ———————————————- For create you could also return the head of the newly created list e.g. N* create(){ N *head; N *newNode; // the same as before return head; } int main() { N *List1 = NULL; // ... do{ scanf("%d",&choose); switch (choose){ case 1: List1 = create(); break;
Anonymous
Hello I want to create 2D doubly linked list but my code is giving segmentation fault
Jaaa
Does anyone explain how does a recursive function work inside a loop
Anonymous
Inside a loop? I suppose you would consider each top level call as an aggrigate, unless it altered loop variable...
Anonymous
Does anyone explain how does a recursive function work inside a loop
Inside a loop, when the function is executed, it will continue to call itself until the termination condition is met, then the next statements of the loop will be executed if any. After, the loop will loop again with the same thing happening previously happening until loop condition becomes false
Jaaa
For loop bro for(int i=0 i<s.length(); i++)
Anonymous
You mean a loop for which i is the control variable. Then it will constantly be updated until condition evaluates to false
Anonymous
There will be no jumping in the loop; everything within the loop's block will be executed sequentially until no more executional statements. Then repetition would occur until condition fails.
Anonymous
It might help to show what you are trying to do, or come up with a Proof-Of-Concept if theoretical question.
Anonymous
Hello I want to create 2D doubly linked list but my code is giving segmentation fault
#include<iostream> using namespace std; class node { public: int data; node *left,*right,*up,*down; }*start = new node; void create(int N,int M,node *start) { start->left = NULL; start->up = NULL; start->down = NULL; node *ptrr = new node; node *ptrd = new node; node *ptr = new node; for(int i=1;i<=N;i++) { for(int j = 1;j<=M;j++) { node *newnode2 = new node; newnode2->data = i*10 + j; if(i==1&&j==1) { start->right = newnode2; } if(i==1) { newnode2->up = NULL; } if(j==M) { newnode2->right = NULL; } if(i==N) { newnode2->down = NULL; } if(j>1) { newnode2->left = ptrr; ptrr->right = newnode2; } if(i>1) { for(int k=1;k<j;k++) { ptr = ptr->right; } ptr->down = newnode2; newnode2->up = ptr; } ptrr = newnode2; if(j==1) { newnode2->left = NULL; ptrd = newnode2; } } ptr = ptrd; } } int main() { create(4,4,start); cout<<start->right->data; }
Anonymous
Till create (3,2) it run fine ... but (3,3) (4,3) etc give segmentation fault
Anonymous
If i had a v recursive function does it go out of the loop to do its work for i= 0 then i=1 and so on... For each value
#include <stdio.h> // recursive Fibonacci int fib(int n) { if(n <= 2) return 1; else return fib(n-1) + fib(n-2); } int main() { for(int i = 0; i < 10; i++) { int x = fib(i); printf("fib(%d) --> %d\n", i, x); } return 0; }
Ammar
Can anyone point out my mistake
I just tried to debug it. Here is last PC when the segfault happens. 47 48 if(i>1) 49 { 50 for(int k=1;k<j;k++) 51 { // ptr=0x00007fffffffe000 → 0x0000000000000000 → 52 ptr = ptr->right; 53 } 54 ptr->down = newnode2; 55 newnode2->up = ptr; 56 57 }
Ammar
Your ptr->right is null. ptr = ptr->right will make your ptr be null. Then you access ptr->right from null pointer, that is why segfault happens.
Ammar
Debugging tip: Compile your source code with -ggdb3 flag. Then run your program under the gdb, by that you will be able to walk into your program easily. g++ -ggdb3 test.cpp -o test gdb test
Anonymous
Oh i have no idea about debug
Ammar
But sir i put ptr = ptrd which is first node of last row...how ptr->right can be null
I don't really know your program flow. I will have to debug it step by step to know this detail. Unfortunately, I don't stand by on my laptop, so can't answer this. You can try to debug it with gdb.
Anonymous
But sir i put ptr = ptrd which is first node of last row...how ptr->right can be null
You *can* make a 2D structure from a binary tree, but it would usually be used for either sorting or sparse data.
Anonymous
A 2D list would look like a list-of-lists, as in lisp: '((1 2 3) (a b c) (x y z))
Anonymous
But i want to create a 2D linked list
Ammar
But sir i put ptr = ptrd which is first node of last row...how ptr->right can be null
BTW, the segfault happens at this values (pay attention to {for-loops variables}). i = 2 j = 4 k = 2 Hope it helps you to give debugging info so you can figure it out.
Anonymous
Thanks! I check
Jaaa
Some of the group member are sending dm kick out them
Ammar
/report This person is sending spam in private message अनवर
Dima
damm same
Dima
/ban 1451732299
Xudoyberdi
Anonymous
BTW, the segfault happens at this values (pay attention to {for-loops variables}). i = 2 j = 4 k = 2 Hope it helps you to give debugging info so you can figure it out.
I got it 🤓 .... I was incrementing ptr j-1 times but when ptr = ptr-> right changing ptr so next time it not need to run it j-1 times