Anonymous
void f(); int main() { int a, b; f(a, b); } void f() { do something; }
Anonymous
works
Mahdi
In my opinion its best usage is when a function doesn't return anything
Anonymous
but void f() { do something; } int main() { int a, b; f(a, b); } is a compile error
Anonymous
In my opinion its best usage is when a function doesn't return anything
What is the advantage or Use of void ? When we can do without void even for the function that doesn't return anything
Anonymous
"An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters" - From C18 standard So int main(){} and int main(void){} are essentially the same
Anonymous
void f(); int main() { int a, b; f(a, b); } void f() { do something; }
@K_P_Shetty this works when you don't write the void inside f(), which is dangerous
Mahdi
What is the advantage or Use of void ? When we can do without void even for the function that doesn't return anything
Functions must have return type. But when a function does not return anything we mark it void to tell nothing returns to the caller
Anonymous
@K_P_Shetty this works when you don't write the void inside f(), which is dangerous
I am dumb, could you please elaborate what is dangerous in it ?
Mahdi
So the advantage is execution speed will be better?
It is not advantage. It is the rule.
Mahdi
You have to use void for function returning nothing
Anonymous
@K_P_Shetty this works when you don't write the void inside f(), which is dangerous
It is actually Undefined Behavior. When you say it works, I hope you meant to say that it compiles fine
Mahdi
Ok 👍
👌✋
ʟᴏɴᴇᴡᴏʟꜰ
https://www.quora.com/What-is-the-use-of-void-in-c
Anonymous
But here he is using int main(void) for every program with return 1 at the end...I am right now working for array programs
Anonymous
Because the function is returnable but has no parameters
Ok thanks, if parameters exists in the programs then we should avoid void ?
Anonymous
I am dumb, could you please elaborate what is dangerous in it ?
https://en.wikipedia.org/wiki/Undefined_behavior there are entire languages designed to avoid undefined behaviour in all but specifically marked lines of code (Rust, Zig)
ʟᴏɴᴇᴡᴏʟꜰ
Yes
Anonymous
Ok thanks, if parameters exists in the programs then we should avoid void ?
You have it the other way round. In C, if a function takes no parameters and you are declaring it without a definition then you should use void in the paremeter list. If you are defining it, you can use either an empty parameter list or void in the parameter list. Both essentially mean the same.
ʟᴏɴᴇᴡᴏʟꜰ
You can leave the parameters region empty it will work even if you don't use void there
Anonymous
You can leave the parameters region empty it will work even if you don't use void there
Not if it is a function declaration in C where an empty parameter list is construed as an unknown number of arguments of unspecified types.
ʟᴏɴᴇᴡᴏʟꜰ
Okay
Anonymous
But here he is using int main(void) for every program with return 1 at the end...I am right now working for array programs
There is nothing wrong with it. Though the general practice is for programs that successfully complete to usually return 0 and a non zero return from main usually means an error condition. But if you don't use the return value in some other program, it doesn't matter what integer value you return from main.
Anonymous
Fine 😊 Thanks a ton for everyone, had many ideas on it 🙏🙏🙏
Anonymous
@ REX
Anshul
Can anyone suggest what is the best place to learn the core subjects for interview preparation?
olli
Can anyone suggest what is the best place to learn the core subjects for interview preparation?
Cracking the coding interview is a great book for interview preparation
Suyash
Cracking the coding interview is a great book for interview preparation
Yeah..! But Personality & Motivation/Confidence is also play big roll
Luiz
Thanks rose😅😊
Ajay
Thank you @MissRose_bot Read the pinned message
Anshul
Cracking the coding interview is a great book for interview preparation
Does that cover cse subjects like DBMS OS because I'm from electrical engineering
olli
Does that cover cse subjects like DBMS OS because I'm from electrical engineering
no, I would not consider DBMS to be a "core subject" for general interviewing. and neither is OS. it does cover basics of C++, Threads, Locks, Data structures and so on. (TOC)
Anshul
no, I would not consider DBMS to be a "core subject" for general interviewing. and neither is OS. it does cover basics of C++, Threads, Locks, Data structures and so on. (TOC)
Ok but I am covering data structures for some other course. Can you suggest me how to have a basic knowledge of DBMS OS computer network. Because they're asked in interview
バレンタインがいない柴(食用不可)
Time for late lunch
Anonymous
pii means pair<int, int> vector<vector<pii>> par(N); WORKS: par = vector <vector<pii>>(n, vector<pii>(m, {0, 0})); DOESN'T WORK WHEN I PUT UNDER NESTED LOOPS WITH THIS: par[i][j].first = 0; par[i][j].second = 0; Tested with par[i][j]={0,0}; too
Anonymous
#include<iostream.h> #include<conio.h> void main() { long int n; cout<<"enter mob_no"; cin>>n; if(n!=11) { cout<<"you entered more than 10 digits"; } else { cout<<" your mobile no is:"<<n; } }
Anonymous
pii means pair<int, int> vector<vector<pii>> par(N); WORKS: par = vector <vector<pii>>(n, vector<pii>(m, {0, 0})); DOESN'T WORK WHEN I PUT UNDER NESTED LOOPS WITH THIS: par[i][j].first = 0; par[i][j].second = 0; Tested with par[i][j]={0,0}; too
Can't help you much with the information you have given. But I think the problem is that you are trying to access elements that don't exist when indexing into the vectors. vector<vector<pii>> par(N) Here par is a vector of length N of empty vectors of pii. So when you use indexes i and j into this vector par, the index j refers to non existing elements.
kj
Shall i use strlen()?
one method is to take input in string and use the .length() function
kj
there are various ways of doing the same thing
Anonymous
👍
kj
if n>10000000…
this could also be done
kj
It work5
good..
Anonymous
Guys one more doubt!
Anonymous
How to use != operator?
Anonymous
In programing
DEV 7
Guys one more doubt!
means not equal to
DEV 7
In programing
for example i=5,j=6; if(i!=j){ cout<<" not equal"; }
Rocky
.
Hanz
Hey guys, I'm in need of someone who can be contacted on a small daily basis for C related understanding -- not problems, I can try to solve it by myself If anyone can help me with this, feel free to inform me via PM or just mention me here. I need serious person, not anonymous one. Thank you
Hanz
Is there something wrong with asking here?
My school ask me for a mentor, that's why. Community can't be included, I already asked that to my Institute
Anonymous
ohh no.
ohh yes
Ayushee
Hello😁
Ayushee
I need someone who can help me learn C program
Ayushee
Is there anyone?
Ayushee
I know fundamentals but still kind of confused with it.
Ayushee
I also wanna know if you guys can provide me hints about how and where can i apply my knowledge of c program!
Ayushee
Ok
Sergeant Stedenko
Has anyone a PDF of the 'C Programming Guide' by Dr Jack Purdum?
Sergeant Stedenko
klimi
Has anyone a PDF of the 'C Programming Guide' by Dr Jack Purdum?
https://archive.org/details/cprogrammingguid00purd is tis sufficient?
Nameful
I know fundamentals but still kind of confused with it.
The best way is really to learn on your own, and then ask when you have specific questions