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
Ehsan
is there bigger datatypes in C? @Tazmikar
do you know any consumer pc/laptop that supports 128 bit data processing?
Anonymous
nah
Anonymous
but there are ways of making a 128 bit int
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 :(
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(); }
Anonymous
#include<iostream> using namespace std; int main(){ int n; cin>>n; int arr[n]; cout<<arr.size(); }
1) the n must be a compile-time constant. 2) arr is just an array, it does not have any members (such as .size()). use std::vector<int> arr; arr.resize(n); to fix both (1) and (2) to only fix (2) either wrap your array with an std::span or use std::size() on the array or use std::array<> to declare the array
Anonymous
or int256 even
use gnu multiprecision library
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
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
something like Here are your answers: 1. Correct 2.Incorrect 3.Correct
You can store each result in a vector and print them at the end
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
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"
References are alias for other objects. You can't use a literal as a default value for references unless the reference is a const reference If you want to give the lvalue reference parameters a default value then you must specify an object with static lifetime (for ex a global variable)
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.
DEV 7
Why don't you try out the code on your compiler?
I try but according to me the answer is 101 105 and compiler give 101 104
Anonymous
I try but according to me the answer is 101 105 and compiler give 101 104
The compiler is correct. You are using a post increment operator which increments a value but returns the old value.
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
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
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)
Pavel
How about I try i-1 and i?...let me try
arr[i-1] will also be out of bounds if your i can equal to zero
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
if (arr[i] > largest) { largest = arr[i]; }
Got this logic as well... thanks!
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++.
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
Anonymous
We are all learning here
I am beginners that's why i am asking.
Anshul
How is "c in depth" book