Harshit
Ya that's the point
Declaring complete name space can sometimes have adverse effects on speed and the linked output might not run as expected for larger programs (where similar functions from different namespaces can collide).
https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
Harshit
Harshit
Oh
Harshit
Practice stuff! That's great
Anonymous
Shubh
Shubh
Shubh
Harshit
Harshit
Your function can have local namespace declarations if you prefer it that way
Harshit
my_func() {
using namespace std;
cout << "AAAA" << endl;
}
Harshit
Anonymous
Harshit
Llvm clang or gcc ?
Harshit
Anonymous
Harshit
During runtime? I am not sure but yeah during linking the final asm object it can.
Anonymous
Harshit
Yeah
Harshit
Not execution, even if it does I might be unaware it should basically be negligible since the modern compilers are pretty smart
Harshit
Compilers basically strip out unneeded stuff and symbols from final assembly so in theory hit shouldn't be there
Anonymous
Yeah
Well even the compilation time is not affected much because by the time the compiler gets to compiling your code where it determines which particular namespace you are referring to, all the used names have already been buit into an AST after the parsing stage. So the lookup is pretty simple. Yes overload resolution and stuff may need to happen but the compilation time is not affected much either.
"Using namespace std" is bad for the reasons listed in that Stackoverflow link you sent. It can result in collisions and in surprise resolutions when you upgrade to a newer version of a library that you are using. Speed is seldom a concern.
Harshit
Agreed there
EYE LORD
What's the best ide for c++
EYE LORD
EYE LORD
Peace
Can we get how much time does our program is taking to do something ? Because If I use binary, I can do much faster ... but I want to check the time taken for binary computation too.
Jasur Fozilov 🐳
Peace
Миршохид
Anonymous
Hello guys
Nomid Íkorni-Sciurus
Guys is it possible to use WinUI 3 with C++ without WinRT/.NET/having to build it as an app rather than a regular executable?
EYE LORD
EYE LORD
Nomid Íkorni-Sciurus
Nomid Íkorni-Sciurus
DevC++ is too ancient and moreover, it is abandoned
EYE LORD
EYE LORD
Nomid Íkorni-Sciurus
Then please suggest me an ide
vscode, codelite, codeblocks, Qt, CLion, Visual Studio, emacs (I'm not including vim because emacs supports more workflows than vim, I wouldn't really consider vim an IDE), Komodo IDE, many more you could google for
EYE LORD
Peace
use profiler
bro, you can explain what is profiler. don't shy.
Pavel
bro, you can explain what is profiler. don't shy.
https://en.wikipedia.org/wiki/Profiling_(computer_programming)
Depending on what IDE/compiler/OS that you use you can have different options of what profiler to use. For example Visual Studio has it own profiler integrated into IDE, you can google what profiler is available to you and how to use it
SMS
Anonymous
// Shared via Compiler App https://g633x.app.goo.gl/TPlw
#include <stdio.h>
#include <malloc.h>
typedef struct node_tag {
int val;
struct node_tag * next;
} node;
node * head;
int main () {
int i,n, before, after, itemBefore, itemAfter, itemDelete;
void insertAtHead(int );
void insertBefore (int, int);
void insertAfter (int, int);
void traverse(void);
void deleteItem(int item);
scanf("%d",&n);
scanf("%d",&itemBefore);
scanf("%d",&before);
scanf("%d",&itemAfter);
scanf("%d",&after);
scanf("%d",&itemDelete);
insertAtHead(0);
for(i=2;i<=n;i+=2)
insertAfter(i,i-2);
traverse();
insertAfter(itemAfter,after);
traverse();
return 0;
}
/* your functions go here */
/* Please use the traverse function provided below so that there is no confusion in output */
void traverse (void) {
node * n = head;
while (n) {
printf("->%d",n->val);
n = n->next;
}
}
void insertAtHead(int t)
{
struct node_tag *n=(struct node_tag*)malloc(sizeof(struct node_tag));
n->val=t;
n->next=head;
head=n;
}
void insertAfter(int a,int b)
{
struct node_tag *n=(struct node_tag*)malloc(sizeof(struct node_tag));
node *p=head;
while(p)
{
if(p->val==b)
{
p->next->val=a;
p->next->next=NULL;
p->next=n;
}
p=p->next;
}
}
Anonymous
Please tell me what is error here
Anonymous
Create a singly linked list of integer values. Implement functions for inserting at the head of the list,
inserting an element before or after another specified element in the list, deleting a given element
and simple list traversal.
Anonymous
This is the question
j
Who can do a c++task
Max
#include <stdio.h>
#include <stdio.h>
int comp(const void * a, const void * b){
return *((char *)a) - *((char *)b);
}
int main(int argc, char const *argv[])
{
int rows = 0, cols = 0;
scanf("%d%d", &rows, &cols);
const int NUM_ROWS = rows;
const int NUM_COLS = cols;
int matrix[NUM_ROWS][NUM_COLS];
char matrix2[NUM_ROWS*NUM_COLS];
int k = 0, sum = 0, count1 = 0, count2 = 0, tmp = 0;
for (int i = 0; i < NUM_ROWS; i++)
{
for (int j = 0; j < NUM_COLS; j++)
{
scanf("%d", &matrix[i][j]);
}
}
printf("\n");
// алгоритм и вывод результата здесь
for (int i = 0; i < NUM_ROWS; i++)
{
for (int j = 0; j <= NUM_COLS / 2; j++)
{
if( j <= i && j <= NUM_ROWS - i - 1){
printf("%d ", matrix[i][j]);
sum+=matrix[i][j];
}
}
printf("\n");
}
for (int i = 0; i < NUM_ROWS; i++)
{
for (int j = 0; j < NUM_COLS; j++)
{
matrix2[k] = matrix[i][j];
printf("%d ", matrix2[k]);
k++;
}
}
qsort(matrix2, NUM_ROWS * NUM_COLS, sizeof(*matrix2), comp);
for (int i = 0; i < k; ++i)
{
printf("%d ", matrix2[i]);
}
//printf("%d %d %d",tmp,sum,count1);
return 0;
}
Max
Hwo knows why doesn't works qsort?
Max
writes warning: implicit declaration of function 'qsort' [-Wimplicit-function-declaration]
50 | qsort(matrix2, NUM_ROWS * NUM_COLS, sizeof(*matrix2), comp);
Igor🇺🇦
#include <stdio.h>
#include <stdio.h>
int comp(const void * a, const void * b){
return *((char *)a) - *((char *)b);
}
int main(int argc, char const *argv[])
{
int rows = 0, cols = 0;
scanf("%d%d", &rows, &cols);
const int NUM_ROWS = rows;
const int NUM_COLS = cols;
int matrix[NUM_ROWS][NUM_COLS];
char matrix2[NUM_ROWS*NUM_COLS];
int k = 0, sum = 0, count1 = 0, count2 = 0, tmp = 0;
for (int i = 0; i < NUM_ROWS; i++)
{
for (int j = 0; j < NUM_COLS; j++)
{
scanf("%d", &matrix[i][j]);
}
}
printf("\n");
// алгоритм и вывод результата здесь
for (int i = 0; i < NUM_ROWS; i++)
{
for (int j = 0; j <= NUM_COLS / 2; j++)
{
if( j <= i && j <= NUM_ROWS - i - 1){
printf("%d ", matrix[i][j]);
sum+=matrix[i][j];
}
}
printf("\n");
}
for (int i = 0; i < NUM_ROWS; i++)
{
for (int j = 0; j < NUM_COLS; j++)
{
matrix2[k] = matrix[i][j];
printf("%d ", matrix2[k]);
k++;
}
}
qsort(matrix2, NUM_ROWS * NUM_COLS, sizeof(*matrix2), comp);
for (int i = 0; i < k; ++i)
{
printf("%d ", matrix2[i]);
}
//printf("%d %d %d",tmp,sum,count1);
return 0;
}
I think you're missing #include<stdlib.h>
Ritesh
Anyone please multiply two numbers with do while loop
Max
Anonymous
I have this code which says Run time error
Anonymous
How can i solve...
Anonymous
In output console it says 10053 file size limits exceeds
Anonymous
Anyone knows about this error
Anonymous
// Shared via Compiler App https://g633x.app.goo.gl/TPlw
#include <stdio.h>
#include <malloc.h>
typedef struct node_tag {
int val;
struct node_tag * next;
} node;
node * head;
int main () {
int i,n, before, after, itemBefore, itemAfter, itemDelete;
void insertAtHead(int );
void insertBefore (int, int);
void insertAfter (int, int);
void traverse(void);
void deleteItem(int item);
scanf("%d",&n);
scanf("%d",&itemBefore);
scanf("%d",&before);
scanf("%d",&itemAfter);
scanf("%d",&after);
scanf("%d",&itemDelete);
insertAtHead(0);
for(i=2;i<=n;i+=2)
insertAfter(i,i-2);
traverse();
insertAfter(itemAfter,after);
traverse();
return 0;
}
/* your functions go here */
/* Please use the traverse function provided below so that there is no confusion in output */
void traverse (void) {
node * n = head;
while (n) {
printf("->%d",n->val);
n = n->next;
}
}
void insertAtHead(int t)
{
struct node_tag *n=(struct node_tag*)malloc(sizeof(struct node_tag));
n->val=t;
n->next=head;
head=n;
}
void insertAfter(int a,int b)
{
struct node_tag *n=(struct node_tag*)malloc(sizeof(struct node_tag));
node *p=head;
while(p)
{
if(p->val==b)
{
p->next->val=a;
p->next->next=NULL;
p->next=n;
}
p=p->next;
}
}
Your program exhibits Undefined Behavior.
Look at your insertAtHead code. You are not setting head to NULL before starting the first insertion. So head will be pointing to some random location.
In insertAfter, you are setting p->next->val and p->next->next without even checking if these are valid pointers. The only thing you know is that p is valid. This is also wrong.
Nank
Evening everyone
Nank
I've got a problem here
Nank
#include <stdio.h>
#include "Elections.h"
Candidat candidatX1, candidatX2, candidatX3, candidatX4;
void infoCandidat(){
printf("Name candidat1 : ");
scanf("%s", candidatX1.name);
printf("Nomber of votes : ");
scanf("%d", candidatX1.votes);
printf("Name candidat2 : ");
scanf("%s", candidatX2.name);
printf("Nomber of votes : ");
scanf("%d", candidatX2.votes);
printf("Name candidat3 : ");
scanf("%s", candidatX3.name);
printf("Nomber of votes : ");
scanf("%d", candidatX3.votes);
printf("Name candidat4 : ");
scanf("%s", candidatX4.name);
printf("Nomber of votes : ");
scanf("%d", candidatX4.votes);
}
void voteTour1(int votes[4]){
if(candidatX1.votes > 50)
printf("Candidat %s, You've been elected", candidatX1.name);
else if(candidatX1.votes > 12 && candidatX1.votes < 50){
printf("You've not win but you go to the second tour");
if(candidatX1.votes > candidatX2.votes && candidatX1.votes > candidatX3.votes && candidatX1.votes > candidatX4.votes)
printf("Candidat %s, You're 1st in the second tour", candidatX1.name);
else
printf("Candidat %s, You're in the second tour but you're not the first", candidatX1.name);
}
else
printf("OUT ! You're no more in the competition");
}
Nank
when i put candidatX1.votes = 15, I still got the answer that the candidate have been selected even though candidatX1.votes <50
Nank
This is the question
Nank
Legislative elections in a given country obey the following rule:
When one of the candidates obtains more than 50% of the votes, he is elected in the first round.
In the event of a second round, only candidates who obtained at least 12% of the votes in the first round can participate.
You must write a program that allows the entry of the scores of four candidates in the first round. This program will then process candidate number 1 and only him:
He will say if he is elected, beaten, if he is in a favorable waiver (he participates in the second round having arrived in the lead at the end of the first all)
Or unfavorable (he participates in the second round without having been in the lead in the first round
Nank
Anonymous
Sorry. I don't understand
It should be
scanf("%d", &(candidatX1.votes));
and not
scanf("%d", candidatX1.votes);
Likewise for all other candidates.
Nank
Anonymous
Anonymous
Nank
That was definitely a problem
Yes. It was a problem & I've corrected it
But it doesn't correct my problem. I still have the answer that the candidate is been elected even though he doesn't have more than 50 votes