Nils
Well you forgot to initialise variables
Emir
int a; a = add(&linkedlist, sayi); i did that and it that work
Emir
int a; a = add(&linkedlist, sayi); i did that and it that work
why should i do that like this? what is the reason
Nils
You have to initialise your variable "linkedlist"
Nils
I don't really know how to do that in your case a I did not dig deep into your code but that's what the error says
Emir
LL linkedlist; init(&linkedlist); i initialise that way, call by reference
Nils
simply do: int secim = 0;
Also you should do this
Nils
Btw I did not read your error correctly first, so sorry for the confusion
Nils
@alkalemir okay, try that first: int secim = 0; I have the feeling that'll solve it
Nils
Even though it looks like it's unrelated, but error messages are weird sometimes.
Emir
but i dont know reason
Nils
Okay, interesting 🤔
Nils
but i dont know reason
I wonder about it too
Emir
I wonder about it too
maybe someone can help us about this error 😄
Anonymous
Anonymous
Anyone know that
Anonymous
help me
Magupalli
Got it
Anonymous
#include<studio.h> int main() { printf("%c", 5["CodingLogic"]); return 0; } Can someone explain the printf statement?
Anonymous
Arrays are basically syntactic sugar in a way
Anonymous
Basically assume an array a[] a[5] actually is *(a+5)
Anonymous
But here's the interesting thing
Anonymous
5[a] becomes *(5+a)
Anonymous
Which is basically the same thing
Anonymous
So u mean to say *(a+5) and *(5+a) both are same?
Anonymous
Tl;dr a[5] = 5[a] = *(a+5) = *(5+a)
Anonymous
They're the same
Anonymous
"Codinglogic" is a string literal but it can be used as an array too
Anonymous
So 5["Codinglogic"] means the 6th element from the string literal and the %c printf format specifier prints the 6th element
Anonymous
Remember that arrays start at 0
Anonymous
The output is g
Anonymous
Ok thanks bro
Anonymous
Also other mistakes you made: Did you mean #include <stdio.h> You don't need to return 0 for main (not a mistake) Keep the { on the same line unless the function name is longer than 80 characters
Sweety
Also other mistakes you made: Did you mean #include <stdio.h> You don't need to return 0 for main (not a mistake) Keep the { on the same line unless the function name is longer than 80 characters
returning 0 is the best practice it says the operating system that the program is executed and when you close the terminal in background it stops the execution of the program.
Anonymous
Main is a special case If you reach the end of main it is automatically returned
Anonymous
There are cases such as looping code inside main where return 0 at the end would become unreachable code
Anonymous
For any other function with a non void return type not returning a value is undefined behavior
Anonymous
As for return types
Anonymous
Values are not sent to the operating system
Anonymous
The return value goes to the caller
Anonymous
When you return from main you're returning a value to whoever called the program
Anonymous
And you don't use the operating system to call your program You'd use a terminal, a file explorer or something else to call the linker entry point
Anonymous
Ohh I didn't know these things.
There was a time when they did but these days you don't even see the operating system
Sweety
Sweety
Anonymous
It will be 0
Sweety
No
So waht will be the returning value and on what factors it depends
Anonymous
Your book is probably teaching C89
Anonymous
You should read up on C99
Sweety
It will be 0
but if the program is exectued successfully.
Sweety
You should read up on C99
The book second part contain this.
Sweety
So waht will be the returning value and on what factors it depends
If the program is not executed successfully what will be tge returning value.
Anonymous
#include <error.h> int main() { errno=5; }
Anonymous
Will return 0
Sweety
Always 0
So, Why we use returning values in C ?
Anonymous
So, Why we use returning values in C ?
For that you must learn about the processor
Anonymous
When you call something the caller transfers control to what was called When a return is used the control is sent back to the caller
Anonymous
yes i read it in functions but what is the use of return of main
Well something has to call main to start the program
Anonymous
When you return you are returning control back to the caller
Anonymous
This is much more visible in a terminal
Anonymous
When the program runs you don't see the shell
Anonymous
If you're in bash and run this program the return value goes in ?
Sweety
The shell
it is for windows/linux
Anonymous
You can access ? by $? echo $?
Anonymous
Or printf $?
Sweety
Can you suggest me something book/blog for what happens in behind when a program is executed ?
Rahul
#include <stdio.h> int main() { int n1,n2; char ope; printf("Enter first number : "); scanf("%d",&n1); printf("Enter second number : "); scanf("%d",&n2); printf("Enter opertaion + , - , * \n"); scanf("%s",&ope); switch(ope) { case '+' : printf("\n\nAddition is : %d ",n1); break; case '-' : printf("\n\nSubtraction is %d ",n1-n2); break; case '*' : printf("\n\nMultiplication is %d ",n1*n2); break; default : printf("\n\nInvalid operation entered"); break; } return 0; }
Rahul
Can you please explain why my output is coming wrong ?