Anonymous
yeah that works
Talula
Here it'll take input and in case only enter is press it'll show enter is pressed... it is just an if statement.
Anonymous
what is string datatype?
Anonymous
is that only in C++?
Talula
is that only in C++?
Yes... same can be done in C if you check if first char of array of char is '\0'
Anonymous
is there bigger datatypes in C? @Tazmikar
Anonymous
like int128_t uint64_t is too small
Anonymous
nah
Anonymous
but there are ways of making a 128 bit int
Ehsan
Ehsan
you can make an array of two int64
Anonymous
there are math libraries for other languages that allow int256_t too
Ehsan
and make a wrapper around it to make it easy to insert values
Anonymous
C doesn't have any libs haha
Anonymous
#include <locale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
setlocale(LC_NUMERIC, "");
for (uint64_t i = 1; true; i *= 2)
{
printf("%'ld\n", i);
usleep(300000); // Sleep for 0.3 seconds
if (i == 4611686018427387904)
{
return EXIT_SUCCESS;
break;
}
}
}
Anonymous
this overflow early :(
Ehsan
Anonymous
i want int128_t
Anonymous
or int256 even
Anonymous
i'll try your array solution tomorrow
Ehsan
okay make an array and make a wrapper around it
Ehsan
you can accept numbers as String and then convert them
Anonymous
type casting?
Anonymous
Python doesn't seem to ever overflow because its dynamically typed
Anonymous
So you can calculate super high numbers with ease
Anonymous
Arrays are so cool they allow for so much
Vikas
#include<iostream>
using namespace std;
int main(){
int n; cin>>n;
int arr[n];
cout<<arr.size();
}
Vikas
Luca
hello guys I would like to pass the pointer of an instance of class A to a class B without calling any copy constructor or assigment operator, something like:
class B{
A &a;
public:
B(A *a): a(a) { }
}
int main(){
A a{};
B b{a};
.....
But i'm getting an error
Anonymous
Anonymous
class B {
A *a_ = nullptr;
public:
B(A *a): a_(a) { }
};
int main() {
A a{};
B b{&a};
Jagadeesh
what's mean macros in c
Stay Forward
Preprocessor directive
Harvina
hi everyone, I would like to ask for some guidance and assistance with my program
Harvina
i have created a quiz program in C++ but I cannot figure out how to make my program print the answers in the end
Harvina
something like
Here are your answers:
1. Correct
2.Incorrect
3.Correct
Captain
Harvina
artemetra 🇺🇦
i'm passing an argument to a function by reference, how do i set its default value?
example:
void writeHeader(uint32_t& x_size, uint32_t& y_size, uint32_t& rgb_max_value = 255){
gives me an error on "255", "initial value of reference to non-const must be an lvalue"
DEV 7
int a = 100;
int *p = &a;
int **q = &p;
int b = (**q)++ + 4;
cout << a << " " << b << endl;
Options:
0. 100 104
1. 101 104
2. 101 105
3. 100 105
why option 1 is correct , why not option 2
Anonymous
artemetra 🇺🇦
artemetra 🇺🇦
Mar!o
Anonymous
it will also work with rvalue references
Yes it will. I was just explaining the error message he got. And moreover it doesn't make sense to have rvalue references as parameters and pass a default literal value in. If you use a rvalue reference parameter you most likely want to move a value into the function.
Mar!o
Anonymous
DEV 7
ok
Ssssss
int n;
cin>>n;
int* p= new int[n];
now the question is how to send this dynamically allocated array in a function?
Anonymous
#include<iostream>
using namespace std;
void fn(int*k)
{
cout << k[0];
}
int main()
{
int n;
cin >> n;
int* p= new int[n];
p[0] = 12;
fn(p);
}
Kartik
for(int i = 0; i < N; i++){
if(arr[i] < arr[i+1]){
largest = arr[i+1];
}
else {largest = arr[i];}
}
Is this logic correct for getting largest of n elements in array
Pavel
Pavel
And not set it, if the array element is less than largest
Kartik
Largest = -1....that's what I did
I tried comparing with largest but still I got wrong number
Kartik
Pavel
Also arr[i + 1] will go out of bounds
Kartik
How about I try i-1 and i?...let me try
Pavel
Means??
if (arr[i] > largest) { largest = arr[i]; }
Pavel
That's the only thing that you need in your loop, in the end largest will be the value of the largest element
Pavel
You will need to give it some very small value before the loop though, or assign the first element to it (then you can start the loop from the second element)
Kartik
Anonymous
#include <iostream>
#include <cstdlib>
#include <sstream>
using namespace std;
int main()
{
int* arr = new int[10];
for (int i = 0; i<10; i++) {
arr[i] = rand() % 100;
}
int max = arr[0];
for (int i = 0; i<10; i++) {
if (max < arr[i]) max = arr[i];
}
stringstream ss;
for (int i = 0; i<10; i++) {
ss << arr[i] << ",";
}
ss << "\n";
ss << "max = " << max;
cout << ss.str();
delete [] arr;
}
Kartik
Ssssss
Ssssss
Anonymous
Hello everyone i am new to c++ ..can anyone help me to learn c++.
Kartik
you are right
Anonymous
hello
Idowu Oluwarimi Joshua
Hello
Anonymous
I am new to group and new to c++ can anyone help me with c++.
Kris
Joshua
Hello guys I'm new to object oriented programming in c++ I was wondering if anyone could suggest me a learning website or material if you can thank you
Anshul
How is "c in depth" book