Nils
Well you forgot to initialise variables
Emir
int a;
a = add(&linkedlist, sayi);
i did that and it that work
Emir
Nils
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
Nils
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
Emir
but i dont know reason
Nils
Okay, interesting 🤔
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
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
Anonymous
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
Sweety
Sweety
Sweety
Anonymous
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
Anonymous
Anonymous
#include <error.h>
int main() {
errno=5;
}
Anonymous
Will return 0
Sweety
Always 0
So, Why we use returning values in C ?
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
Sweety
Anonymous
Anonymous
When you return you are returning control back to the caller
Anonymous
This is much more visible in a terminal
Sweety
Anonymous
When the program runs you don't see the shell
Anonymous
Anonymous
If you're in bash and run this program the return value goes in ?
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 ?