Remember to initialize the pointer

Source: Internet
Author: User

Tag: Address error RoCE turned test program initial highlight

Today, in the writing sequence stack, the beginning of the formal parameter is passed through the address, that is, with Seqstack &s Pass, and then see the online useful pointers to pass, so want to change to use the pointer to pass.

Problem came, when I put all the S.top s.data modified to S->top s->data, Seqstack &s modified to Seqstack *s run, with the codeblocks, the operation is not error, but do not print out the elements in the stack, Run one to return to Process returned-1073741819 (0xC0000005) error exit. In order to find the exact location of the error, I added printf () to find the problem, that is, as long as the run to have s->top or s->data to exit unexpectedly. Because the stack is to be initialized, execution to S->top =-1 o'clock in Initstack (Seqstack *s) exits unexpectedly.

What's the problem? So I wrote a simple test procedure in my writing.

#include <stdio.h>typedef int datatype;typedef struct{    DataType data;    int top;} Seqstack;int Main () {    seqstack *s;    Remove the annotation program for normal operation output 1   //seqstack address;   S = &address;    S->data=;    S->top = 1;    printf ("%d%d", S->data, S->top);}

The problem is that there is no pointer to the definition being initialized. How do you judge if a pointer is not initialized?

The following is the author's idea, in Codeblocks run the exit returned is the process returned-1073741819 (0xC0000005), then the other, then wrote a program to test.

#include <stdio.h>int main () {    int *a, B;    b = +;    A = &b;    printf ("%d", *a);}

After running, the same is returned error Process returned-1073741819 (0xC0000005), then there will be no wild pointer, there is this error AH. The author Baidu A bit, found that this error is related to memory, then the wild pointer is not pointing to a deleted object or not requesting access to restricted memory area.

So this error is related to memory, so when this problem occurs, it is advisable to check the memory-related statements.

Of course, it's important to have a good programming habit!!! When defining pointers, be sure to initialize, the default value of the wild pointer is random, it will randomly point to a pass, regardless of whether the address is legitimate, so the operation of the wild pointer can easily cause a program error!!

  

Remember to initialize the pointer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.