Hi,
I have a structure as follows.
typedef struct {
int a;
char *c;
int s;
}MEDIA;
main()
{
MEDIA m, n;
char c[] = "feroz";
m.a = 5;
m.c = c;
m.s = 10;
n = m; ->>>>> is this valid?
}
can i use "=" operator to copy data of "m" to "n"?...
User Profile
Collapse
-
Can we copy structures with "=" operator?
-
>>That's right, the const just modifies how the program >>can interact with the variable, not where the data is >>stored (on PCs).
Moving back to basics,you mean if i have a code like
void foo(void)
{
const int x = 10;
}
My "x" still be stored on stack, but the only difference is "x" cannot be changed am I right? -
Banfa,
Actually, I have a global linked list, I need to return pointer to a data member for a given node.
I can't have my entire code here, so i have given a code snippet similar to what I have.
>>You don't return a pointer to local data, you return a pointer to global data.
You mean to say, my code works fine all the time if i remove 'const', since I'm returning pointer to a global member?Leave a comment:
-
Return a const pointer from a function
Hi, Let me know if there is any thing wrong with this code snippet.
1. Will this code works fine every time?
2. Returning "ptr" will be dangling?
3. Where my "ptr" is stored? in Read-Only data segment/stack/some where else?
=============== =============== =============== ============
Code:#include <stdio.h> int a = 20; int *foo(void) { const int *ptr
No activity results to display
Show More
Leave a comment: