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).
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
Pavel
where is the text "abc" allocated in memory?
In the part of the memory where the executable is loaded I believe https://en.cppreference.com/w/cpp/language/string_literal
Anonymous
String literals are located neither on a stack or a heap
But for simplicity think that it's a stack memory
Anonymous
But for simplicity think that it's a stack memory
tell me where is it actually allocated?
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
because you got it wrong
Would love to hear that, Dima
Anonymous
I'm beginner for C language
Anonymous
hello
Nohello.com
Anonymous
How I should start my learning
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
Because string literals are already const char*
Yeah I lied It's not a const char* it's const char[n+1] where n is a number of symbols in a string literal
Anonymous
when you say string literal you mean something inside "" or something else. I want to clarify this.
Anonymous
ok so anything inside "" is a const char[n+1]
Anonymous
right?
Anonymous
There was a link for you
So I' right in saying that anything inside "" is a const char[n+1];
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
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
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?
Anonymous
Any c-array decays to a pointer to the first element of the array
Anonymous
"abc" already returns a pointer, you don't need to get pointer of that pointer
int x = 9; int *p = &x; int *c = p; I'm saying that content of p is getting assigned to c. and you're blaming me to speak that address of p is getting assigned to c. This is wrong.
Anonymous
I meant to say the 1st statement.
Anonymous
Anonymous
Yes
Anonymous
Yes
Thanks for clarifying the doubt.
Abhi
Hi
Anonymous
Hi
Nohello.com
Anonymous
Yeah I lied It's not a const char* it's const char[n+1] where n is a number of symbols in a string literal
Hey ! Danya Why is "abc" considered const char * and not const char[n+1] ?