#include <errno.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> void Print(int* buf, int len) { printf("Value(int)= "); for(int i=0; i<len; ++i) { printf("%d", buf[i]); } printf("/n"); } void Print(char* buf, int len) { printf("Value(char)= "); for(int i=0; i<len; ++i) { printf("%c", buf[i]); } printf("/n"); } int main(int argc, char** argv) { printf("scale variable:/n"); //1. scale variable char v1; // not initialization. Value depends on compiler Print(&v1, 1); char v2 = '1'; // user initialization Print(&v2, 1); char* v3 = new char; // not initialization. Value depends on compiler Print(v3, 1); char* v4 = new char(); // zeroing initialization. value is 0; Print(v4, 1); char* v5 = new char('A'); // user initialization Print(v5, 1); int* i5 = new int(1243214); // user initialization Print(i5, 1); printf("array variable:/n"); //2. array char a[10]; // not initialization. Value depends on compiler Print(a, 10); char b[10] = {}; // same as {0}; zeroing initialization. Print(b, 10); char b1[10] = {'a'}; // b[0]='a', other is 0! Print(b1, 10); char* c = new char[10]; // not initialization. Value depends on compiler Print(c, 10); char* d = new char[10](); // zeroing initialization. Print(d, 10); // char* e = new char[10]('a'); // Error: ISO C++ forbids initialization in array new // Print(e, 10); return 0; }