zoukankan      html  css  js  c++  java
  • C++第二章理论题错题整理3

    The keyword extern is not a definition and is not allocated storage until it is initialized.

    No extern are allowed for class declarations.

    In statement 1 lvalue is required as unary ‘&’ operand and in statement 3 lvalue is required as left operand.

    int (*fp)(char*)

    pointer to function taking a char* argument and returns an int

    * is used as dereferencing operator, used to read value stored at the pointed address.

    A pointer can be in only 3 states: hold the address of the specific object  point one past the end of an object  zero

    Array element cannot be address of auto variable. It can be address of static or extern variables.

    An array is a series of elements of the same type in contiguous memory locations

    int array[] = {10, 20, 30};
    cout << -2[array];

    It’s just printing the negative value of the concern element.

    Size of any type of pointer is 4 bytes in 32-bit platforms.

    cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];

    a是一个二维数组,并且这三个表达式代表的是同一个元素。

    const char *arr[] = {"C", "C++", "Java", "VBA"};
    const char *(*ptr)[4] = &arr;
    cout << ++(*ptr)[2];

    最后输出的是ava.

    int numbers[5];
           int * p;
           p = numbers;  *p = 10;
           p++;  *p = 20;
           p = &numbers[2];  *p = 30;
           p = numbers + 3;  *p = 40;
           p = numbers;  *(p + 4) = 50;
           for (int n = 0; n < 5; n++)
               cout << numbers[n] << ",";

    访问数组中元素的各种用法。

    Other name for Constants are literals.

    The const will declare with a specific type value and #define is used to declare user-defined constants.

    L prefix can declare a wide character in the string literal.

    Reference is a thing which points to the valid memory address, so it can’t be redesigned.

    we can not create the array of reference

    References require are other names for variables not for a constant literal. No such assignment are allowed in C++. (即不能直接给一个int&赋值一个整数)

    Every reference should be initialized during its declaration but as p is not initialized here therfore the program gives error.

    A pointer cannot be directly assigned to references, because types of pointer(int*) and reference(int) are different here. You need to think before assigning two variable of different types otherwise the program throws error.

    The program is correct so the the program runs perfectly. It is way to assign pointers to references. The program prints the address of a because it is an alias for pointer p and pointer p stores the address of a therefore answer is address of a.

    References are an alias for a variable whereas pointer stores the address of a variable

    References uses no * operator to access the value of variables it is refering to therefore no program gives error as we are using * operator.

    In this program as one parametere is passed by value and other is passed by reference so after 4 calls when c == 0, then the value of x = 7 and as x is passed by reference so all the changes will be reflected back in all the previous calls hence the answer 1*7*7*7 = 343.

    A variable can have multiple references as references are nothing just another name for a variable hence a variable can more than one references.

    By casting the pointer to another data type, it can be dereferenced from the void pointer.

    Pointer can point to any variable that is not declared with const & volatile.

    A void pointer can point to methods & class member in c++.

        #include <iostream>
        using namespace std;
        int func(void *Ptr);
        int main()
        {
            char *Str = "abcdefghij";
            func(Str);
            return 0;
        }
        int func(void *Ptr)
        {
            cout << Ptr;
            return 0;
        }

    这一段代码最后会得到Str的地址。

    The void pointer is easily converted to any other type of pointer, so these are equal.

    Because the void pointer is used to cast the variables only, So pointer arithmetic can’t be done in a void pointer.

    The structure declaration with open and close braces and with a semicolon is also called structure specifier.

    Character classification provides isspace() function to check whether a character in C++ is tab or space or whitespace control code( , , etc.).

    Character classification provides isprint() function to check whether a character in C++ is printable on console.

    Character classification provides isxdigit() function to check whether a character in C++ is hexadecimal.

  • 相关阅读:
    跨平台技术
    Unity和虚幻的比较
    商业模式(四):群硕软件,欧美客户为主的软件外包
    商业模式(四):群硕软件,欧美客户为主的软件外包
    Volley完全解析
    双十一京东图书购物清单,动动脑子节省300元
    双十一京东图书购物清单,动动脑子节省300元
    ListView异步加载图片,完美实现图文混排
    使用DrawerLayout实现QQ5.0侧拉菜单效果
    商业模式(三):P2P网贷平台,毛利润测算
  • 原文地址:https://www.cnblogs.com/hhlys/p/13449033.html
Copyright © 2011-2022 走看看