Index | Prev | Next

C & C++ Programming

Write a c program to print your name but without using semicolon


    #include "stdio.h"
    
    void main()
    {
        if(printf("Hello World")) 
        { }
    }
            

Const Pointer - Predict the output or error(s) for the following:

    void main() 
    {
        int nCount = 5;
        int const* ptr = &nCount;
        cout << *ptr << ++(*ptr) << endl;
    }
    error C3892: 'ptr' : you cannot assign to a variable that is const
            
  • CApache const* ptr means "ptr points to a constant CApache": the CApache object can't be changed via ptr.
  • CApache* const ptr means "ptr is a const pointer to a CApache": you can't change the pointer ptr, but you can change the CApache object via ptr.
  • CApache const* const ptr means "ptr is a constant pointer to a constant CApache": you can't change the pointer ptr itself, nor can you change the CApache object via ptr.

Write a program to convert lower case string to upper

    char ConvertToUpperCase(char ch) {
       if (ch >= 'a' && ch <= 'z')
          ch = ch - 'a' + 'A';
       return ch;
    }
            
Index | Prev | Next