`

System level Programming study(1)

阅读更多
1. 内存分配导致无意 修改数据,无限循环:
#define ARRAY_SIZE 10
void natural_numbers (void{
  
int i;
  
int array[ARRAY_SIZE];

  i 
= 1;
  
  
while (i <= ARRAY_SIZE) {
       array[i] 
= i - 1;
       i 
= i + 1;
  }

}



2.  C语言中,string是character array ,必须明确终止,错误程序:
     
#include <stdio.h>
#include 
<string.h>

#define MAXLINE_LENGTH 80

char Buffer[MAXLINE_LENGTH];

char * readString(void)
{
    
int nextInChar;
    
int nextLocation;

    printf(
"Input> ");
    nextLocation 
= 0;
    
while ((nextInChar = getchar()) != '\n' &&
       nextInChar 
!= EOF) {
        Buffer[nextLocation
++= nextInChar;
    }

    
return Buffer;
}



int main(int argc, char * argv[]) 
{
  
char * newString;
  
  
do {
      newString 
= readString();
      printf(
"%s\n", newString);
  }
 while (strncmp(newString, "exit"4));
  
return 0;
}
Fix it,在while循环上加赋空语句:
memset(Buffer,NULL,MAXLINE_LENGTH*sizeof(char));

3.指针引用:
#include <stdio.h>
#include 
<iostream.h>
void Initialize (char * a, char * b)
{
    a[
0= 'T'; a[1= 'h'; a[2= 'i';
    a[
3= 's'; a[4= ' '; a[5= 'i';
    a[
6= 's'; a[7= ' '; a[8= 'A';
    a[
9= '\0';
    b 
= a;
    cout
<<b<<endl;//this is A
    b[8= 'B';
    cout
<<b<<endl;//this is B
}


#define ARRAY_SIZE 10
char a[ARRAY_SIZE];
char b[ARRAY_SIZE];

int main(int argc, char * argv[])
{
    Initialize(a, b);
    cout
<<b<<endl;  // print nothing
    return 0;
}
分享到:
评论

相关推荐

    C.Programming.The.Ultimate.Way.to.Learn.C.1500481114

    I promise this book will make you 100% expert level champion of C Programming. This book contains 1000+ Live C Program’s code examples, and 500+ Lab Exercise & 200+ Brain Wash Topic-wise Code book ...

    C.Programming.The.Definitive.Beginners.Reference.1500481009

    I promise this book will make you 100% expert level champion of C Programming. This book contains 1000+ Live C Program’s code examples, and 500+ Lab Exercise & 200+ Brain Wash Topic-wise Code book ...

    Architecture Support for Task Out-of-Order Execution in MPSoCs

    Multi-processor system on chip (MPSoC) has been ... Examples and a JPEG case study demonstrate that our model can largely ease the burden of programmers as well as uncover the task level parallelism.

    Handbook of Big Data Technologies

    4 Case Study: Stream Processing with Apache Flink 5 Applications, Trends and Open Challenges 6 Conclusions and Outlook Part II Semantic Big Data Management Semantic Data Integration 1 An Important ...

    C.in.Depth.Easy.Beginners.To.Experts.Guide.1500481033

    I promise this book will make you 100% expert level champion of C Programming. This book contains 1000+ Live C Program’s code examples, and 500+ Lab Exercise & 200+ Brain Wash Topic-wise Code book ...

    Learning.Java.by.Building.Android.Games

    Walk through the fundamentals of building games and use that experience as a springboard to study advanced game development or just have fun Who This Book Is For If you are completely new to either...

    Java 9 for Programmers (Deitel Developer Series) 完整高清azw3版

    Written for programmers with a background in another high-level language, this book applies the Deitel signature live-code approach to teaching programming and explores the Java® 9 language and APIs ...

    Itanium Architecture For Programmers

    Why Study Assembly Language? Section 1.4. Prefixes for Binary Multiples Section 1.5. Instruction Set Architectures Section 1.6. The Life Cycle of Computer Architectures Section 1.7. SQUARES: ...

    Internet Infrastructure_Networking, Web Services, and Cloud Computing-CRC2018

    Finally, there are books on socket-level programming. This textbook attempts to combine the aspects of the rst and second groups mentioned previ- ously. We do so by dividing the material roughly into...

    Multiprocessor+Systems-on-Chips

    7.3 System-Level Analysis for Designing Communication Architectures 194 7.3.1 Trace-Based Analysis of Communication Architectures 196 Contents xi 7.4 Design Space Exploration for Customizing ...

    英语口语试题集锦.doc

    So I think further study is still urgent for me to realize self-value. The major that I hope to pursue for my further education is IC design. Because I find integrated circuits are playing an ...

    Professional Ajax

    Professional Ajax 2nd Edition provides a developer-level tutorial of Ajax techniques, patterns, and use cases. The book begins by exploring the roots of Ajax, covering how the evolution of the web and...

    Object-Oriented Software Construction 2nd

    Chapter 21: Inheritance case study: “undo” in an interactive system 695 21.1 PERSEVERARE DIABOLICUM 695 21.2 FINDING THE ABSTRACTIONS 699 21.3 MULTI-LEVEL UNDO-REDO 704 21.4 IMPLEMENTATION ASPECTS ...

    Python: End-to-end Data Analysis.azw3电子书下载

    Data analysis is the process of applying logical and analytical reasoning to study each component of data present in the system. Python is a multi-domain, high-level, programming language that offers ...

    Structured Spark Streaming-as-a-Service with Hopsworks

    - **HopsFS (Hadoop File System):** A distributed file system designed for high-performance data access. HopsFS integrates seamlessly with Spark and other big data frameworks. - **YARN (Yet Another ...

Global site tag (gtag.js) - Google Analytics