Pavel
olli
Anonymous
Hey. I am beginner and do not even know the alphabets of programming. Can somebody help md learn the basics.
mov $22, %rax
mov $22, %rax
There were a few problems I solved
Vlad
Anonymous
I mean i do not know anything but i want to start learning
Vlad
Anonymous
😢
Vlad
Programming books cover the basics after you got them down sky is the limit, also almost anything can be google'd if you know how to ask
MUSTAFA
Help
MUSTAFA
Program calculates all prime numbers less than x
klimi
Артём
Read about friend declaration.
Vlad
Maybe you'll show it, lol
Anonymous
hi guys, anyone around? i've got a doubt
Vlad
struct foo
{
// declaration
friend std::istream& operator>>(std::istream& from, foo& f);
}
// implementation
std::istream& operator>>(std::istream& from, foo& f)
{
//... read from stream
return from;
}
Vlad
you can, but why?
Anonymous
srry you were talking and i didnt want to interrupt
Anonymous
but here it goes
Vlad
Why would you override cin for it?
Vlad
std::cin is meant for a retrieval of data
Vlad
Wouldn't std::cout be for it?
Anonymous
I cant grasp the idea of why arrays are non-modifiable lvalues... I've read some documentation online and I know it has something to do with C predecessor B.
I didnt get if the name of the array is just a constant number or what.
I get what lvalues/rvalues are, I get how pointers work but I dont understand why in the name of god I cant do smth like this:
int x[10];
int y[10];
x = y;
Vlad
struct foo
{
// declaration
friend std::ostream& operator<<(std::ostream& to, const foo& f);
}
// implementation
std::ostream& operator<<(std::ostream& to, const foo& f)
{
//... write into from stream
return to;
}
Vlad
That's how it's done if you want to print out your class
Vlad
Vlad
Anonymous
I dont, Im just trying to understand why arrays are non-modifiable lvalues, that just the example I came up with
Vlad
Anonymous
the doubt struck me when I tried to used an array as a pointer
Vlad
Then why give it a special case?
Anonymous
so the lvalue error showed
Vlad
You can add a level of indirection (malloc into int* and swap arrays back and forth)
Anonymous
yes I know
Vlad
Arrays on stack however cannot be reassinged
Vlad
Memory is there already
Anonymous
I can do all through pointers
Anonymous
yeah but basically the name of the array is the address of the 1st element
Anonymous
or "points" to that address
Anonymous
then why I cant use the array as a pointer?
Vlad
Vlad
So they more of
int * const
Vlad
Because what does it even mean to change an address of existing array on the stack
Vlad
It's meaningless
Anonymous
yeah sure it has no purpose
Anonymous
ok I gotta read more about why is a const pointer though
Anonymous
I mean I get it but wanna know the WHY
Vlad
Anonymous
gotcha, thx m8!
Anonymous
Different countries use different coin denominations. For example, Bangladesh uses 1, 2, and 5. A desirable property of coin denominations is to have each coin at least twice the amount of its previous coin in sorted order. For example, the Bangladesh coin denominations have this property, but the coin denominations {1, 5, 6} do not (6 is not at least twice 5).
The Problem:
Given the coin denominations, you are to determine if the set has the above property.
Input Format
The first input line contains a positive integer, n, indicating the number of denomination sets to check. The sets are on the following n input lines, one set per line. Each set starts with an integer d , which is a count of various coin amounts in the set; this is followed by d distinct positive integers (each less than 1,000) giving each coin amount (assume the coin amounts are given in increasing order).
Constraints
(1 ≤ d ≤ 10)
Output Format
At the beginning of each test case, output “Denominations: v” where v is the input values. Then, on the next output line, print a message indicating whether or not the set has the above property. Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output.
Sample Input 0
2
4 1 5 10 25
3 1 5 6
Sample Output 0
Denominations: 1 5 10 25
Good coin denominations!
Denominations: 1 5 6
Bad coin denominations!
(can anyone plz solve this c program)
Vlad
Different countries use different coin denominations. For example, Bangladesh uses 1, 2, and 5. A desirable property of coin denominations is to have each coin at least twice the amount of its previous coin in sorted order. For example, the Bangladesh coin denominations have this property, but the coin denominations {1, 5, 6} do not (6 is not at least twice 5).
The Problem:
Given the coin denominations, you are to determine if the set has the above property.
Input Format
The first input line contains a positive integer, n, indicating the number of denomination sets to check. The sets are on the following n input lines, one set per line. Each set starts with an integer d , which is a count of various coin amounts in the set; this is followed by d distinct positive integers (each less than 1,000) giving each coin amount (assume the coin amounts are given in increasing order).
Constraints
(1 ≤ d ≤ 10)
Output Format
At the beginning of each test case, output “Denominations: v” where v is the input values. Then, on the next output line, print a message indicating whether or not the set has the above property. Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output.
Sample Input 0
2
4 1 5 10 25
3 1 5 6
Sample Output 0
Denominations: 1 5 10 25
Good coin denominations!
Denominations: 1 5 6
Bad coin denominations!
(can anyone plz solve this c program)
Assignment solvers two blocks down
tartaerae
Hello, i'm beginner
I want to ask, an example this array is:
char vowel[5]="aiueo"
char konsonan[21]="bcdfghjklmnpqrstvwxyz"
these array can be collected into one array??
tartaerae
Okay thankyou
Aakash
char a[N];
char b[M];
// create an array that could fit contains of both
char newarr[(sizeof(a) + sizeof(b) + 1)]; // +1 for '\0'
// copy contents of these arrays into the new one
memcpy(newarr, a, sizeof(a));
memcpy(newarr + sizeof(a), b, sizeof(b));
// add '\0' so printing it won't make your pc on fire
newarr[sizeof(newarr) - 1] = '\0';
Example!
char A[] ="string";
char B[11] ="string";
char C[] ={'s', 't', 'r', 'i', 'n', 'g', '\0'};
char D[11] ={'s', 't', 'r', 'i', 'n', 'g', '\0'};
For A & B '\0' NULL is added automatically, but in other case it needs to be added explicitly.
—-now your case!!
You are using +1 or should it be +2?!!😄
Aakash
Example!
char A[] ="string";
char B[11] ="string";
char C[] ={'s', 't', 'r', 'i', 'n', 'g', '\0'};
char D[11] ={'s', 't', 'r', 'i', 'n', 'g', '\0'};
For A & B '\0' NULL is added automatically, but in other case it needs to be added explicitly.
—-now your case!!
You are using +1 or should it be +2?!!😄
@VoidStar0x0
Here is my justification!!
——
include <stdio.h>
#include <string.h>
int main(void)
{
char A[7] = "hello\n";
char B[7] = "hello\0";
char C[7] = "hello";
printf("\n---A");
printf("Array[size]: %d, Str[Len]: %s[%d]", sizeof(A), A, strlen(A));
printf("\n---B");
printf("Array[size]: %d, Str[Len]: %s[%d]", sizeof(B), B, strlen(B));
printf("\n---C");
printf("Array[size]: %d, Str[Len]: %s[%d]", sizeof(C), C, strlen(C));
return 0;
}
Updated!!
Vlad
Example!
char A[] ="string";
char B[11] ="string";
char C[] ={'s', 't', 'r', 'i', 'n', 'g', '\0'};
char D[11] ={'s', 't', 'r', 'i', 'n', 'g', '\0'};
For A & B '\0' NULL is added automatically, but in other case it needs to be added explicitly.
—-now your case!!
You are using +1 or should it be +2?!!😄
why +2?
Vlad
string has only one terminator
Vlad
Also this string doesn't have a terminator, because he explicitly wrote a size without it
char vowel[5]="aiueo"
Vlad
Vlad
And if you set the size smaller printf starts misbehaving
Vlad
Which is to be expected as there's no null at the end
Vlad
So to resume: char C[5] = "hello"; does not have a null terminator
Aakash
So to resume: char C[5] = "hello"; does not have a null terminator
If you say there is not NULL termination! And printf() is misbehaving try cout!!
—
include <iostream>
#include <string.h>
using namespace std;
int main(void)
{
char A[7] = "hello\n";
char B[7] = "hello\0";
char C[7] = "hello";
char D[(sizeof(B) + sizeof(C) + 1)];
cout << "\n---A";
cout << "Array[size]:" <<sizeof(A) << " Str:"<<A <<"|len:" <<strlen(A);
cout << "\n---B";
cout << "Array[size]:" <<sizeof(B) << " Str:"<<B <<"|len:" <<strlen(B);
cout << "\n---C";
cout << "Array[size]:" <<sizeof(C) << " Str:"<<C <<"|len:" <<strlen(C);
return 0;
}
—-[1] modify & compile
char A[7] = "hello\n";
char B[6] = "hello\0";
char C[7] = "hello";
—-[2 modify & compile
char A[7] = "hello\n";
char B[7] = "hello\0";
char C[5] = "hello";
😄
Vlad
Vlad
And if you do so it does the same deal as with printf
Vlad
Who would have thought
Vlad
'Cause it comes down to this loop in the puts function
char temp;
while(temp = *ptr++) putc(temp);
Aakash
Who would have thought
Try this!! & find how many NULL do you see in Bx & Cx..
include <iostream>
#include <string.h>
using namespace std;
int main(void)
{
char A[7] = "hello\n";
char B[7] = "hello\0";
char C[7] = "hello";
cout << "\n---A";
cout << "Array[size]:" <<sizeof(A) << " Str:"<<A <<"|len:" <<strlen(A);
cout << "\n---B";
cout << "Array[size]:" <<sizeof(B) << " Str:"<<B <<"|len:" <<strlen(B);
cout << "\n---C";
cout << "Array[size]:" <<sizeof(C) << " Str:"<<C <<"|len:" <<strlen(C);
cout <<"\n---BX" <<endl;
for(int i=0; i<(sizeof(B)); i++) {
cout <<" B-Str:" <<B[i] <<endl;
if(B[i] == '\0')
cout <<"shout NULL" <<endl;
}
cout <<"\n---CX" <<endl;
for(int i=0; i<(sizeof(C)); i++) {
cout <<" C-Str:" <<C[i] <<endl;
if(C[i] == '\0')
cout <<"shout NULL" <<endl;
}
return 0;
}
😄 try changing size too..
Aakash
Vlad
Vlad
Or it just magically happens to be this way?
Aakash
Vlad