Saurabh
// main.c #include <stdio.h> extern void show(); int main() { show(); return 0; }
Msd
Hi friends suggest me website to learn c++ I am intermediate
Saurabh
Nikita are you saying this?
Saurabh
something like this??
%Nikita
Why extern needed?
Saurabh
cz it tells the compiler to search for the function in others files too
Saurabh
Does header do the same?
can you plz elaborate your doubt about header?
Saurabh
are you talking about including the function prototype declaration in some header file and then using that header in some other program ?
Saurabh
Yes
in that case, no need of extern keyword. Just include the header containing the functions you want to use
%Nikita
Friends
Don’t know C++. I know only good YouTube channel to learn C
Saurabh
Friends
javatpoint - for reading reference learning lad - video lectures
Saurabh
%Nikita
Ok nikita
Channel called “Jacob Sorber”. I think one of the best C practices
Saurabh
And if I am not using #include? gcc main.c function.c
can you send me the snap of your code, as I am not getting your doubt properly
%Nikita
can you send me the snap of your code, as I am not getting your doubt properly
I was trying to explain, sorry if I confuse you a bit
Msd
Channel called “Jacob Sorber”. I think one of the best C practices
Okay but I need c++ my company placed me in c++ project
Saurabh
I was trying to explain, sorry if I confuse you a bit
better you send your source code and then refer the doubt in the code
%Nikita
can you send me the snap of your code, as I am not getting your doubt properly
I mean what difference between these two lines: void foo(void); extern void foo(void);
Saurabh
I mean what difference between these two lines: void foo(void); extern void foo(void);
void foo(void); is the prototype declaration when the function is itself defined in the same file. while extern void foo(void); is used when you have defined your function in some other file and now you want to use that function in the file where it is not defined!
Saurabh
I hope this clears your doubt
Saurabh
pleasure to solve someone's doubt
%Nikita
I agree :)
Anonymous
Hi
Msd
#include<iostream> #include<string> using namespace std; int main() { string name; int words = 1; int i; cout << "Enter the paragraph :"; getline(cin,name); cout << "\nyou have entered : " << name << endl << endl; for (i=0; i<name.size(); i++) { if((int) name[i] == 32 ) { words++; } } cout << "The total number of words you have entered is : " << words; return 0; } Friends I want to count the number of sentence But it giving 1 count extra Please help me
RØB
Gap before %c in scanf
Can you tll more clear ?
Suraj
Can you tll more clear ?
#include<stdio.h> int main() { int a,b; char op; printf("enter any two number :"); scanf("%d%d",&a,&b); printf("enter any arithmetic op[ + - * / ] :"); scanf(" %c",&op); switch (op ) { case '+': printf("%d+%d=%d",a,b,a+b); break; case '-': printf("%d-%d= %d",a,b,a-b); break; case '*': printf("%d*%d= %d",a,b,a*b); break; case '/': printf("%d/%d= %d",a,b,a/b); break; default : printf("404 ERROR"); } return 0; }
Suraj
Like this
Anonymous
Hey guys! I'm moving from python to C/C++ and I would like an indication of a simple project to train, could someone point me to something to start?
Saurabh
Hey mates! I have a doubt regarding 'dynamic memory allocation'! Consider 2 program given below : program 1 : int num; cin>>num; int arr[num]; program 2 : int num; int *ptr = new int[num]; cin>>num; my doubt : program 2 is considered as dynamic memory allocation. While we can use program 1 too to allocate the memory while in run time. So, can we consider program 1 to be as 'dynamic memory allocation'?? PLEASE HELP!!
מנחם
for (char ltr=0; ltr <= 255; ltr++) cout << ltr; for (int ltr=0; ltr <= 255; ltr++) cout << (char) ltr; Why does the first show go into an endless loop?
Pavel
for (char ltr=0; ltr <= 255; ltr++) cout << ltr; for (int ltr=0; ltr <= 255; ltr++) cout << (char) ltr; Why does the first show go into an endless loop?
First, char can be signed or unsigned, for char you need to always specify signess if it matters to you. Second, signed char is between -128 and 127, unsigned char is from 0 to 255, both always satisfy the condition of the first loop. For unsigned char, if it had value 255 and you do +1, it becomes 0 again (it called overflow). For signed char overflow is undefined behavior.
מנחם
Ahh why you using char in first loop
I want to understand the differences
Pavel
It has, any possible value of char is less or equal than 255, so the loop condition will always be true in the code above
מנחם
my complier converts it Clion
Pavel
Thanks for the excellent explanation. What happens if I do ch=256? Does it automatically reset to 0, ch=256=0?
So by the docs it will be zero for unsigned char, and if it's signed then it is implementation defined (so you basically can't tell for sure) https://en.cppreference.com/w/cpp/language/implicit_conversion See "Internal conversions" the first bullet point But better to avoid cases like this because it just makes your code confusing for people who read it (including you in future)
Michel
Just read the rules, would it be ok to ask something about CUDA C++?
Dima
Yea
José Juan
Hey mates! I have a doubt regarding 'dynamic memory allocation'! Consider 2 program given below : program 1 : int num; cin>>num; int arr[num]; program 2 : int num; int *ptr = new int[num]; cin>>num; my doubt : program 2 is considered as dynamic memory allocation. While we can use program 1 too to allocate the memory while in run time. So, can we consider program 1 to be as 'dynamic memory allocation'?? PLEASE HELP!!
In my humble opinion, the 1st case is not dynamic memory. Let's think of this: how would you modify the size of that array (in run time) in the 1st case? You could not reallocate or free memory for it after creating it. I just did a quick search and found this: https://www.guru99.com/cpp-dynamic-array.html It (inderectly) says that the word "dynamic" is related to manually memory handling in runtime. Since you could not modify the size of int arr[num] after this line, then I would say that dynamic memory is not being applied here. If someone else has something better to say on this it would be nice to compare our points of view, I might be wrong but this is what I understand. Finally you could take a look at this: https://press.rebus.community/programmingfundamentals/chapter/fixed-and-dynamic-arrays/#:~:text=Static arrays have their size or length determined when the array is created and/or allocated. where they said that a static array has its size determine when the array is created.
Leovan
I mean what difference between these two lines: void foo(void); extern void foo(void);
Hm, as far as I know there is no difference. Variables must have extern in declaration, but in functions its not necessary, because function declaration and definition different enough.
olli
I mean what difference between these two lines: void foo(void); extern void foo(void);
there is no difference, a function has external linkage by default so both declarations are the same. // flib.h #ifndef FLIB_H #define FLIB_H // function with external linkage void f(void); #endif // FLIB_H https://en.cppreference.com/w/c/language/storage_duration
Anonymous
Hey mates! I have a doubt regarding 'dynamic memory allocation'! Consider 2 program given below : program 1 : int num; cin>>num; int arr[num]; program 2 : int num; int *ptr = new int[num]; cin>>num; my doubt : program 2 is considered as dynamic memory allocation. While we can use program 1 too to allocate the memory while in run time. So, can we consider program 1 to be as 'dynamic memory allocation'?? PLEASE HELP!!
The latter is also dynamic allocation in that it happens at runtime. The array you have defined in the 1st case is a Variable Length Array. Memory for it is however allocated on the stack and not the heap. Generally, dynamic memory allocation is used to refer to memory allocated on the heap. VLA is not a standard compliant behavior. You should not use it.
Msd
#include <iostream> #include <string> using namespace std; int main() { int words = 1; string paragraph; { cout << "Enter the paragraph :\n"; getline(cin, paragraph); for (int i = 0; i < paragraph.size(); i++) { if (paragraph[i] == ' ') // please explain this step { if (i + 1 < paragraph.size())// please explain this step { if (paragraph[i + 1] != ' ')// please explain this step { words++; } } } } cout << "The total number of words you have entered is : " << words; return 0; } }
Msd
friends i cant understand the 1st if condition
Parra
I have created a channel related to C++ where I'm adding interesting articles and links, is it ok to share it here?
KN
I want to divide 2 binary numbers Like 1001100 by 1010 I want to ask how to take binary numbers as an input?
KN
So that I xan divide these Hope you got my question
KN
*can
Anonymous
I have created a channel related to C++ where I'm adding interesting articles and links, is it ok to share it here?
Can you please share it with one of the admins first? They will circle back to you after checking with the other admins.
Null
Words bro
I don’t if I’m wrong but you can just count the spaces then after the loop is done you just add 1 to the spaces counted 🙂. Like maybe “I Go To School” Spaces will be 3 but just add 1 to the 3 And that’ll make it 4 words🙃
Shahrukh
Yes but I am starting from basic
Shahrukh
I want to divide 2 binary numbers Like 1001100 by 1010 I want to ask how to take binary numbers as an input?
You don't need to take binary input just use bitwise operator on decimal integer