포인터 관련

2041 단어
일.
char* buf1[9] = {"hello", "bestwish"};
buf1+=9;
strlen(buf1)    ==  ?
이.
int* i[10]; int(*j) [10];
설명:
sizeof(i)  ==  ?
sizeof(j)  ==  ?
/* 
 * File:   main.cpp
 * Author: vicky
 * Email:  [email protected]
 */
#include <iostream>
#include <string.h>

/*
 * 
 */
int main(void) {
        char* buf1[9] = {"hello", "bestwish"};
        char* p1 = buf1[0];
        std::cout << p1 << std::endl;
        std::cout << p1 + 10 << std::endl;
        std::cout << strlen(p1 + 10) << std::endl;

        std::cout << "---------------------------" << std::endl;

        char buf2[2][9] = {"hello", "bestwish"};
        char* p2 = buf2[0];
        std::cout << p2 << std::endl;
        std::cout << p2 + 10 << std::endl;
        std::cout << strlen(p2 + 10) << std::endl;


        std::cout << "---------------------------" << std::endl;

        char* names[10] = {"jack", "vicky", "lucy", "lily", "tom", "tony", "nacy", "bill", "anni", "ashi"};
        char** pnames = names;
        for (int i = 0; i < 10; i++)
                std::cout << *pnames++ << std::endl;
        return 0;
}

hello
wish

---------------------------
hello
estwish

---------------------------
jack
vicky
lucy
lily
tom
tony
nacy
bill
anni
ashi
/* 
 * File:   main.cpp
 * Author: vicky
 * Email:  [email protected]
 */
#include <iostream>

/*
 * 
 */
int main(void) {

        int* i[10];
        int(*j) [10];
        
        std::cout << sizeof(i) << std::endl; // 80    32 : 40
        std::cout << sizeof(j) << std::endl; // 8     32 : 4
        
        return 0;
}

좋은 웹페이지 즐겨찾기