zoukankan      html  css  js  c++  java
  • 动态内存的申请与释放必须配对,防止内存泄漏

    动态内存的申请与释放必须配对,防止内存泄漏。

     1 #include <iostream>
     2 #include<stdio.h>
     3 #include <string.h>
     4 
     5 //main()函数
     6 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     7 using namespace std;
     8 int main(int argc, char** argv) {
     9         //声明变量和数组
    10     char  buffer[200], s[] = "computer", c = 'l';
    11     int   i = 35, j;
    12     float fp = 1.7320534f;
    13 
    14     //格式化输出到buffer
    15     j  = sprintf( buffer,     "	String:    %s
    ", s );
    16     j += sprintf( buffer + j, "	Character: %c
    ", c );
    17     j += sprintf( buffer + j, "	Integer:   %d
    ", i );
    18     j += sprintf( buffer + j, "	Real:      %f
    ", fp );
    19 
    20     cout<<"Output:"<<endl;
    21     cout<<buffer;
    22     cout<<"character count ="<<j<<endl;
    23     return 0;
    24 }
  • 相关阅读:
    *Integer to English Words
    *Palindrome Linked List
    *Partition List
    Sort Colors
    wireshark tls
    find 路径必须在表达式之前
    http://mozilla.debian.net/
    maven bundle
    xmpp
    xmlns=""
  • 原文地址:https://www.cnblogs.com/borter/p/9413687.html
Copyright © 2011-2022 走看看