"Data structure and algorithm analysis--c language description" after reading note 2

Source: Internet
Author: User

Information such as "Memory access violation" or "segmentation violation" usually means that a pointer variable contains a pseudo-address. One common reason is that initializing a variable fails.


The result of free (p) is that the address to which P is pointing does not change, but the data at that address is undefined at this time.


Occasionally, when your program uses a lot of space, the system may not meet your requirements for the new unit. A null pointer is returned at this time.


Warning: malloc (sizeof (Ptrtonode)) is legal, but it does not allocate enough space to the struct. It assigns only one space to the pointer.


An array of size n, whose main element is an element that has more occurrences than N/2 (thus having at most one of these elements).

Program 1: Find the main elements of an array

 #include <stdio.h> #define  size 100int main () {     int array[size],i,n,num[10]={0};    printf ("please input  the array size : "); &NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d ", &n);     printf (" Please input the array[%d] :\n ", n);     for (i=0;i<n;++i)    &NBSP;&NBSP;{&NBSP;SCANF ("%d", &array[i]); num[array[i]]++;    }          for (i=0;i<n;i++)     { if (num[i]> (N/2))  {     printf ("the mainelement is : %d\n", i);      return 0;  }    }         printf ("there is no mainelement!\n");      return 0;} 


"Data structure and algorithm analysis--c language description" after reading note 2

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.