Open Means Open Means

Array of string pointers

No comments on “Array of string pointers”
#include 
// Array of string pointers to be sorted.
static const char* brothers[] =
{
    "Frederick William",
    "Joseph Jensen",
    "Harry Alan",
    "Walter Ellsworth",
    "Julian Paul"
};
// Linkage specification.
extern "C"
{
    // Prototype of C function.
    void SortCharArray(const char**);
    // C++ function to be called from the C program
    int SizeArray()
    {
        return sizeof brothers / sizeof (char*);
    }
}
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    // Sort the pointers.
    SortCharArray(brothers);
    // Display the brothers in sorted order.
    int size = SizeArray();
    for (int i = 0; i < size; i++)
        std::cout << brothers[i] << std::endl;
    return 0;
}

Call C function from C++ program

No comments on “Call C function from C++ program”
/*////////////////////////////////////*/
#include
#include
/* Prototype of the C++ function. */
int SizeArray(void);
/*////////////////////////////////////*/
/* The compare function for qsort().  */
/*////////////////////////////////////*/
static int comp(const void *a, const void *b)
{
    return strcmp(*(char **)a, *(char **)b);
}
/*////////////////////////////////////*/
/* C function called from C++ program.*/
/*////////////////////////////////////*/
void SortCharArray(char **List)
{
    int sz = SizeArray();
    qsort(List, sz, sizeof(char *), comp);
}

Assignment and Expression

No comments on “Assignment and Expression”

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    // Declare three integers.
    int HourlyRate;
    int HoursWorked;
    int GrossPay;

    // Assign values to the integers.
    HourlyRate = 15;
    HoursWorked = 40;
    GrossPay = HourlyRate * HoursWorked;

    // Display the variables on the screen.
    std::cout << HourlyRate;
    std::cout << ' ';
    std::cout << HoursWorked;
    std::cout << ' ';
    std::cout << GrossPay;

    return 0;
}

Increment and Decrement Operator in c++

No comments on “Increment and Decrement Operator in c++”

#include

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    int Ctr, OldCtr, NewCtr;

    // Make the assignments
    OldCtr = 123;      // OldCtr is 123
    NewCtr = ++OldCtr; // NewCtr is 124, OldCtr is 124
    Ctr = NewCtr--;    // Ctr is 124, NewCtr is 123

    // Display the results
    std::cout << OldCtr;
    std::cout << ' ';
    std::cout << NewCtr;
    std::cout << ' ';
    std::cout << Ctr;

    return 0;
}

Conditional Operator in C++

No comments on “Conditional Operator in C++”

#include

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    float Dues;      // dues amount

    // Read the dues.
    std::cout << "Enter dues amount: ";
    std::cin >> Dues;

    // Are the dues paid on time?
    std::cout << "On time? (y/n) ";
    char yn;
    std::cin >> yn;
    bool Overdue;   // true if overdue, false if on time
    Overdue = yn != 'y';
    float AmountDue; // amount to be computed

    // Use conditional operator to compute.
    AmountDue = Overdue ? Dues * 1.10 : Dues;

    // Display the dues amount.
    std::cout << "Amount due: ";
    std::cout << AmountDue;

    return 0;
}

More Articles …

  1. Type Conversion
  2. Some basic codes of data structures
  3. what is data structure?
  4. Understanding how compiler was developed
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

Page 19 of 21

  • About Us
  • Faqs
  • Contact Us
  • Disclaimer
  • Terms & Conditions