Alex
otherwise you get UB and potential segfault
Artöm
It is obviously something like hackerrank task, input validation can be omitted there
Alex
What about int arr[N]; instead of int arr[1000];? Is it allowed?
in this case no, N should be macro or const
Anonymous
in this case no, N should be macro or const
I tried it and it showed no problems. But I still don't like that some books forbid it.
Anonymous
so the teacher prompted me that i can in arr[1000];
Sameer
Anonymous
haw i can writ in const form?
Anonymous
so write up to 1000?
Alex
haw i can writ in const form?
constexpr int N = 1000;
Anonymous
#include <iostream> int main() { int N; std::cin >> N; const int arr =1000;
Anonymous
that's right?
Alex
ok
Anonymous
Or<=?
Alex
<=
Anonymous
for( int i = 0; i < N; i++){ std::cin >> arr[i]; } for ( int i = 0; i< N; i++){ std::cout << arr [i] << " "; } }
Anonymous
I seem to have errors here too
Anonymous
I will show the task again
Anonymous
#include <iostream> int main() { int N; std::cin >> N; const int arr =1000; for( int i = 0; i < N; i++){ std::cin >> arr[i]; } for ( int i = 0; i< N; i++){ std::cout << arr [i] << " "; } }
Anonymous
Write a program that gets a natural number N (N ≤ 1000) at the input, then a sequence of whole N elements. As a result, the program must display the sequence in reverse order. Use array to solve the problem
Artöm
arr should be array, not a number
Anonymous
😞
Anonymous
I don’t understand
Pavel
Use it in your latest example
Anonymous
but the compiler says something is wrong
Anonymous
Of course wrong. How do you expect it to deal with arr[i] when arr is an integer?
Anonymous
 clang++-7 -pthread -std=c++17 -o main main.cpp main.cpp:10:18: error: subscripted value is not an array, pointer, or vector std::cin >> arr[i]; ~~~^~ main.cpp:13:21: error: subscripted value is not an array, pointer, or vector std::cout << arr [i] << " "; ~~~ ^~ 2 errors generated. compiler exit status 1 
Anonymous
whot i must to du?
Pavel
Yes ,by using preprocessing
N is known only at runtime, as I understand
Pavel
We can define like this #define N 1000
Don't teach them this prohibited magic :D
Anonymous
We can define like this #define N 1000
I know that. I meant int N; cin>>N; int arr [N]; The point is that the compiler doesn't know the size of the array the moment of compiling.
Sri
Ok
Anonymous
g++ 4.9.2 2014
Pavel
well wait.. it does compile, why?
Anonymous
well wait.. it does compile, why?
Sometimes the problem is that it succeeds when we don't suppose it to.
Pavel
Sometimes the problem is that it succeeds when we don't suppose it to.
OK, my colleagues told me that gcc supports VLA extension (variable-length arrays) that as I understood is part of C standart (C99?) but not part of any C++ standard. So in other words it's only a gcc feature in context of C++.
piggyho
running ++i; on your x86 hardware is not atomic
atomic instructions add assembly code that tell cpu how to order and maintain cache consistency someone new to programming should not pay much attention to this yet. it is complicated. most languages do not expose this level of detail
Anonymous
yes
piggyho
first outcome: 1087851 second outcome: 1031545 third outcome: 1112568 forth outcome: 1071384 fifth outcome: 1155180
if there threads are running in different cores and three cores have the value x in caches for the core then in an indeterminate way they will be incrementing x in that cache when you do mutual exclusion or atomics the processor well make sure that the cache values of x values are synchronized it doesn't matter if heap or stack when program starts the operating system gives it some stack when a function or thread starts that function or thread is given some stack also also when a program starts the runtime makes a call to the operating system and asks for a chunk of memory which this run time makes into a heap the runtime will ask the os for more memory or return some as needed. when the program and that memory was returned to the operating system malloc on Linux first try to do mutual exclusion in user space, see futex, which is faster and then revert to mutual exclusion in the kernel which is slower you can manage your own heap if you want also. the Linux call is sbrk for the chunk of memory
piggyho
that is true the different models exist for different processors, . Intel x86 naturally maintains a lot of cache consistency where is arm powerpc do not
piggyho
I would have to look it up but there's some load in the stores that are cache consistent 4 integral types herb Sutter did a great talk on this. the video is up on YouTube and channel 9
piggyho
thank you
Indolent
What is the significance of modulo operator in the Caesar encryption algorithm?
Indolent
And even before that what is the need of remainder? What good are they?
Indolent
This is cool but hard to grasp.
PO
Who has ever used Gtk?!
PO
In C programing
Anonymous
i need a information about c++
Anonymous
especially where you can find various tasks
Anonymous
Seriously
Anunay
Seriously
He is serious
Alex
especially where you can find various tasks
c++ books usually include exercise after each chapter
Anonymous
ok. for wile prefix postfix const int?
Anonymous
about this
Alexander
https://isocpp.org/wiki/faq/const-correctness
Anonymous
I need tasks and their solutions
Alexander
Task about what? About const? I cant imagine such tasks
Anonymous
If you want to be professional, read Programming principles and practice by Bjarne Stroustrup. Otherwise, I highly recommend you to begin with C++ without fear by Brian Overland.
Anonymous
Thank you so much
Anonymous
What does it say?
you know howe mach I am tride It does not work you can help to write this code?
piggyho
good article. it mentions: for aligned x86 accesses, it is not necessary to consider write/write pairs as competing i will try to find the sutter presentation and seen if i got it worng
@unchanted
how can i solve dining philosopher's problem in c++
@unchanted
do i have to make 5 programs for eac philosopher?
@unchanted
each program for each philosopher*
@unchanted
?
@unchanted
but do I have to create 1 different program for each philosopher?
@unchanted
is there any easier way?
@unchanted
yes, do i need a saparate running process?