User Profile

Collapse

Profile Sidebar

Collapse
FerozAhmed
FerozAhmed
Last Activity: Oct 8 '10, 07:48 AM
Joined: Sep 14 '10
Location: Bangalore, India
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • FerozAhmed
    started a topic Can we copy structures with "=" operator?
    in C

    Can we copy structures with "=" operator?

    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"?...
    See more | Go to post

  • FerozAhmed
    replied to Return a const pointer from a function
    in C
    >>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?
    See more | Go to post

    Leave a comment:


  • FerozAhmed
    replied to Return a const pointer from a function
    in C
    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?
    See more | Go to post

    Leave a comment:


  • FerozAhmed
    started a topic Return a const pointer from a function
    in C

    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
    ...
    See more | Go to post
    Last edited by Banfa; Sep 14 '10, 03:06 PM. Reason: Added [code]...[/code] tags round the code
No activity results to display
Show More
Working...