Ajiq
Anybody here good in java?
Ajiq
I need help
Ilya
Ajiq
In threading
Ilya
#include<iostream>
#include<conio.h>
using namespace std;
void binary(int a[],int lb,int ub,int x)
{
int mid;
while(lb<=ub)
{
mid=(lb+ub)/2;
if(a[mid]==x)
{
puts("yes.");
return;
}
else if(x<a[mid])
binary(a,lb,mid-1,x);
else if(x>a[mid])
binary(a,mid+1,ub,x);
}
if(lb>ub)
puts("not.");
}
int main()
{
int a[15],n,i,x;
printf("Enter the size of array: ");
scanf("%d",&n);
printf("Enter elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter data: ");
scanf("%d",&x);
binary(a,0,n-1,x);
return 0;
}
You have logical error.
Either lb or ub must change in each iteration
Ilya
Sunny
Augmented
hello, is there a problem to use "struct" instead of "class" keyword, if i have only public definitions ? obviously struct acts like class, but it starts public by default, and can use private later, class starts private by default, but can be switched to public or protected... I know how it is working, But in general is there any possible issues, or is it a good practice to use "struct" instead of "class" for shortening the source code lines...
MilkBeforeCereal
only difference is the default visibility label in structures and classes
MilkBeforeCereal
you can use either
MilkBeforeCereal
structures by default is public, classes, private
Augmented
thank you for that clarification
Ilya
Augmented
i will assume these keyword are interchangeable, just default visibility differs, but doesn't affect compilers internal job
Ilya
MilkBeforeCereal
MᏫᎻᎯᎷᎷᎬᎠ
Augmented
i am trying to pack a library code, as much is possible, without violating standarts, and sacrifising readibility...
Augmented
i am trying to get rid of cpp files when its possible, and to impelement functions inside the class definition section...
Augmented
i know it's worses the readability, but i use for just for simple functions, mostly single row...
Ilya
Augmented
i am using this style only for the most basic and simple classes, like FIFO queues, linked list, memory pool etc.., member functions are single row, when i derive and extend that class i am using separate cpp file for function's code body, is it okay?
Augmented
another boring question
Augmented
does #pragma once, works like
#ifndef header_h
#define header_h
.....
#endif
it seems to do the job, but is this a good aproach?
Ilya
Augmented
Yes it does
Great, and it saves 2 rows of source code
Anonymous
I don't think this is a good practice because not all compilers support #pragma once afaik
Dima
Anonymous
Vikram
Best book to learn C and C++ in easy way.. newbie like me
Dima
Augmented
Ok
I use few different compilers, but mostly GCC and G++, and it seem they support that, but is there any cavets from using it?
Vikram
What's this
Anonymous
Anonymous
Augmented
Okay, excuse me for asking dumb questions, i can google that of course, but i prefer information from humans, not machine...
Anonymous
Anonymous
MᏫᎻᎯᎷᎷᎬᎠ
Ok
The manual include guards can be little bit confusing
Consider this example
You have two folders each of which has user.hpp
The first folder is Database contains the functionality that deal with Users table or database under the user.hpp file.
The second folder has the definition of the class User under user.hpp
You have two files with the same name under different folders(no confliction)
When you generate both header files through IDEs
Both of the files has the definition USER_HPP macro
Then if both files were included (and will)
It will cause one of them as it was not pre-processed that implys lots of hard to track compiler errors
Anonymous
MᏫᎻᎯᎷᎷᎬᎠ
Yeah
Anonymous
That's why they are usually prefixed with name of the lib
Anonymous
like BOOST_NOEXCEPT
Ilya
Augmented
Ilya
Besides, #pragma once don't have explicit end , so it can only switch off the entire source file
Augmented
Anonymous
https://pastebin.com/afTfim57 Can`t figure out! error: array type 'char [46]' is not assignable. More details about error in the end of the code. Can someone help me? I find that I can solve this problem using function strcpy but how can I do this correct?
Ilya
Ilya
Anonymous
Anonymous
#include <stdio.h>
void printer (int *p,int *q)
{
int x=*p+6;
int y =*q-30;
printf(“%d\n”,x);
printf(“%d\n”,y);
}
void subprint(int *x,int *y)
{
*x=*y/7;
*y=*y*3;
printf(“%d\n”,x);
printer(&*x,&*y);
printf(“%d\n”,*x+1);
printf(“%d\n”,*y-2);
}
void print(){
int x =42;
int y=x/11;
subprint(&y,&x);
printf(“%d\n”,y);
printf(“%d\n”,x);
}
int main () {
int x =17;
int y=84;
print();
return (0);
}
Anonymous
I cnt get output ..
Dima
#include <stdio.h>
void printer (int *p,int *q)
{
int x=*p+6;
int y =*q-30;
printf(“%d\n”,x);
printf(“%d\n”,y);
}
void subprint(int *x,int *y)
{
*x=*y/7;
*y=*y*3;
printf(“%d\n”,x);
printer(&*x,&*y);
printf(“%d\n”,*x+1);
printf(“%d\n”,*y-2);
}
void print(){
int x =42;
int y=x/11;
subprint(&y,&x);
printf(“%d\n”,y);
printf(“%d\n”,x);
}
int main () {
int x =17;
int y=84;
print();
return (0);
}
/warn Lol read the rules
バレンタインがいない柴(食用不可)
Hi, I've been a developer from the JAva background and have been picking up C++ since last year. I think for the basic C++ (pointers, OOP, ..etc) I'm able to master that well, but feel I need to polish up my skill on the newest C++ releases (e.g. C++ 17) because i've had difficulty employing the best practice.
Are you able to suggest me a good book to continue with my learning? Thanks!
Anonymous
Anonymous
It's called "effective modern C++" by Meyers
Anonymous
It's a good one, but it's C++14 only
バレンタインがいない柴(食用不可)
oh wow i'm also googling this book at the same time!
バレンタインがいない柴(食用不可)
@unterumarmung thanks man ;)
Anonymous
I suggest you to watch CppCons as well, it will boost your knowledge
Augmented
hi again friends, another silly question from me:
if "," is used instead of ";" to separate operations (not when defining variables), is the execution order preserved e.g.
crc >>= 4, crc ^= Table[idx], crc += 1234;
Will this execute as ";" was used to separate the three operations? I like to use "," to keep the expression on single row after code refactoring and "beautification"... it looks more atomic, when there are few operations to the same variable, instead of writing as single expression like:
crc = ((crc>>4)^table[idx]) + 1234; What you think about that?
Ilya
Anonymous
https://pastebin.com/MBKQTrt1
Anonymous
https://pastebin.com/v34djD8f