MᏫᎻᎯᎷᎷᎬᎠ
What are they?
Anonymous
I need to add
Function
add(a[],b[],int n,int m) in this program
Anonymous
#include <stdio.h>
void main()
{
int i, j, m, n, o, p;
printf("Enter the no. of row and column of 1st matrix:");
scanf("%d,%d", &m, &n);
printf("Enter the no. of row and column of 2nd matrix:");
scanf("%d,%d'", &o, &p);
if (m == o && n == p)
{
int a[m][n];
printf("Enter the first matrix\n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &a[i][j]);
}
}
int b[m][n];
printf("Enter the second matrix\n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &b[i][j]);
}
}
int sum[m][n];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
sum[i][j] = a[i][j] + b[i][j];
printf("%d\t", sum[i][j]);
}
printf("\n");
}
}
else
printf("Matrix cant be added");
}
Pavel
I hear a lot about reflections in the upcoming versions of C++
Reflection is knowing of classes structure in runtime (like self-reflection in philosophy when you think about how your body and mind works)
E.g. it would be helpful sometimes to iterate over member variables (for serialization or debug purposes), that C++ can't do now and every projects has it own workarounds for that (e.g. I use code generation for lot of my classes and enums).
MᏫᎻᎯᎷᎷᎬᎠ
Dima
Pavel
You mean like generating classes at runtime?!
nope, I use code generation as a crunch to solve some problems that could be otherwise easier solved by reflection
I mean accessing the structure of a class at runtime
like in these examples from other languages
https://en.wikipedia.org/wiki/Reflection_(computer_programming)
.
hi
.
which is best refernce like boook/youtube channel to learn algorithims and datastructures in c
Anonymous
I am learning cpp strings and before that I learnt that "abcd" is a const char*
Anonymous
this comes out from C
Anonymous
and doing const char* p = "abc"
Anonymous
Yes
Anonymous
is perfectly fine.
Anonymous
where is the text "abc" allocated in memory?
Anonymous
stack memory?
Anonymous
or inside heap?
Anonymous
in cpp is it compulsory that it is just new operator that will allocate things in heap?
Anonymous
If yes, then "abc" must be inside stack. Is that so?
Anonymous
String literals are located neither on a stack or a heap
Anonymous
Anonymous
Anonymous
Anonymous
It has a static storage duration
Anonymous
Why did you care to learn it? learning is the primary key.
learning cpp is not the only objective.
Anonymous
And I believe that it is implementation-defined where string literals are located
Anonymous
Also
Anonymous
It is just kind of weird how & "address of" operator is not used before "abc".
Like:
const char *p = &"abc";
Student like me when see this: const char *p="abc" think that
int *p = 8;
should have been perfectly fine which is actually not the case.
bcz we cannot assign an integer to a integer pointer and this reason looks perfect to me.
but seeing const char *p = "abc" confuses me on why the address of operator is not used here?
Dima
because you got it wrong
Anonymous
hello
Anonymous
Anonymous
I'm beginner for C language
Anonymous
Anonymous
How I should start my learning
Anonymous
Anonymous
I hope "abc" is normally stored in memory and the base address of "abc" must be something.
Anonymous
so that & give the base address of location where "abc" is located
Anonymous
Do you understand a connection between pointers and c-style arrays?
Anonymous
nope
Anonymous
#include <stdio.h>
int add(int a[][], int b[][],int n,int m)
{
int i, j;
int sum[n][m];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
sum[n][m] = a[n][m] + b[n][m];
}
}
return sum[i][j];
}
int main()
{
int m, n, o, p, i, j;
printf("Enter the no. of row and column of 1st matrix:");
scanf("%d,%d", &n, &m);
printf("Enter the no. of row and column of 2nd matrix:");
scanf("%d,%d'", &o, &p);
if (n == o && m == p)
{
int c[n][m];
printf("Enter the first matrix\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
scanf("%d", &c[i][j]);
}
}
int d[n][m];
printf("Enter the second matrix\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
scanf("%d", &d[i][j]);
}
}
printf("%d\t", add(c[i][j],d[i][j],n,m);
}
else
printf("Matrix can't be added");
}
Anonymous
Need help to get output
Anonymous
#include <stdio.h>
int add(int a[][], int b[][],int n,int m)
{
int i, j;
int sum[n][m];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
sum[n][m] = a[n][m] + b[n][m];
}
}
return sum[i][j];
}
int main()
{
int m, n, o, p, i, j;
printf("Enter the no. of row and column of 1st matrix:");
scanf("%d,%d", &n, &m);
printf("Enter the no. of row and column of 2nd matrix:");
scanf("%d,%d'", &o, &p);
if (n == o && m == p)
{
int c[n][m];
printf("Enter the first matrix\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
scanf("%d", &c[i][j]);
}
}
int d[n][m];
printf("Enter the second matrix\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
scanf("%d", &d[i][j]);
}
}
printf("%d\t", add(c[i][j],d[i][j],n,m);
}
else
printf("Matrix can't be added");
}
No
You should paste it via paste.ubuntu.com
Anonymous
when you say string literal you mean something inside "" or something else. I want to clarify this.
Anonymous
Anonymous
ok so anything inside "" is a const char[n+1]
Anonymous
right?
Anonymous
Anonymous
~??
Anonymous
So, const char* p = "abc" somehow converts to :
const char *p = const char[n+1]; (I know that we cannot right that.)
So const char[n+1] decays to a pointer and gives the base address of a string literal.
and hence const char *p captures the address of the string literal.
Right?
Anonymous
English?
Anonymous
Anonymous
I want to learn C language can give me the tips how to start
Anonymous
can you*
Anonymous
Get a book.
Anonymous
And do some project. To be practical
Евгений
Anonymous
nope buddy.
Anonymous
So, that means const char[n+1] gives the base address and just that.
Anonymous
Is that so?
Anonymous
Anonymous
Any C-array can be implicitly converted to a pointer
Anonymous
So, is it decaying or just const char[n+1] gives address to const char *p?
Anonymous
which one is correct?
Pavel
Anonymous
Any c-array decays to a pointer to the first element of the array
Anonymous
I meant to say the 1st statement.
Anonymous
Anonymous
Anonymous
Anonymous
Yes
Anonymous
Yes
Thanks for clarifying the doubt.
Abhi
Hi
Anonymous
Anonymous
Anonymous