Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:53:58+00:00 2026-06-07T14:53:58+00:00

#include<stdio.h> struct a { void *ptr; unsigned long val; }; void main() { unsigned

  • 0
#include<stdio.h>

struct a
{
    void *ptr;
    unsigned long val;
};

void main()
{
    unsigned char errno;

    struct a *id;
    id = malloc(sizeof(*id));
    func2(id);
    printf("After changing %d\n", id->val);
}


void func2(struct a *id)
{
    unsigned char errno;
    func(id,&errno);
}

void func(struct a *id,void *ptr)
{   
    memset(id, 0, sizeof(*id));

    id->ptr = ptr;
    if (sizeof(id->val) >= sizeof(id->ptr))
    {   
        id->val = (unsigned long)id->ptr;
        return;
    }

}

when i am printing id->val in main function it is printing -1075050593
. But i am trying to access a invalid address. Please explain. I am very new to c programming.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:54:00+00:00Added an answer on June 7, 2026 at 2:54 pm

    The following statement is not attempting to access an invalid address, it is just printing the address:

    printf("After changing %d\n", id->val);
    

    what value it will hold is unknown as id is being incorrectly passed to func2().

    Some problems with the code (some already mentioned in the comments):

    • incorrectly taking address of id when passing to func2() as id is already a struct a*
    • implicit declarations of memset() and malloc() as missing include directives
    • implicit declarations of func() and func2()
    • return type of main() should be int
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is something like this possible in C? #include <stdio.h> void print_str(char *str) { printf(str);
Code: #include<stdio.h> #include<malloc.h> struct details{ char *name; int no; struct details *info; }; //ADDING
#include <stdio.h> struct context; struct funcptrs{ void (*func0)(context *ctx); void (*func1)(void); }; struct context{
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }; void insert( struct
I compiled this (gcc compiler): #include <stdio.h> main() { struct { a:1; b:2; }
my test code is below: main1.c: #include <stdio.h> extern struct tt ; int main()
#include<stdio.h> #include<conio.h> #include<alloc.h> struct node { int data; struct node*link; }; void push(struct node*,int);
I have: #include <stdio.h> struct DVD { char *movie_title; int minutes; float price; };
#include<stdio.h> #include<conio.h> union abc { int a; int x; float g; }; struct pqr
I was just looking at this example from Deitel : #include <stdio.h> struct card

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.