1. What is C strings syntax?

Strings are arrays of chars. String literals are words surrounded by double quotation marks.
"This is a static string"
To declare a string of 49 letters, you would want to say:
char string[50];

2. How to access a variable of the structure?

To access a variable of the structure it goes:

name_of_single_structure.name_of_variable;
For example:
struct example {
int x;
};
struct example an_example; //Treating it like a normal variable type
an_example.x = 33; //How to access its members

3. What is format for defining a structure?

The format for defining a structure is:

struct Tag {
Members
};
Where Tag is the name of the entire type of structure and Members are the variables within the struct. To actually create a single structure the syntax is
struct Tag name_of_single_structure;

4. What is general format for a prototype?

The general format for a prototype is simple:
return-type function_name ( arg_type arg1, ..., arg_type argN );
arg_type just means the type for each argument -- for instance, an int, a float, or a char. It's exactly the same thing as what you would put if you were declaring a variable.

5. What is prototype for that C string function?

The prototype for that function is:
istream& getline(char *buffer, int length, char terminal_char);
The char *buffer is a pointer to the first element of the character array, so that it can actually be used to access the array. The int length is simply how long the string to be input can be at its maximum (how big the array is). The char terminal_char means that the string will terminate if the user inputs whatever that character is. Keep in mind that it will discard whatever the terminal character is.

It is possible to make a function call of cin.getline(arry, 50); without the terminal character. Note that 'n' is the way of actually telling the compiler you mean a new line, i.e. someone hitting the enter key.

For a example:
#include <iostream>

using namespace std;

int main()
{
char string[256]; // A nice long string

cout<<"Please enter a long string: ";
cin.getline ( string, 256, 'n' ); // Input goes into string
cout<<"Your long string was: "<< string <<endl;
cin.get();
}</endl;
</iostream>

6. How one would use switch in a program?

#include <iostream>

using namespace std;

void playgame()
{
cout << "Play game called";
}
void loadgame()
{
cout << "Load game called";
}
void playmultiplayer()
{
cout << "Play multiplayer game called";
}

int main()
{
int input;

cout<<"1. Play gamen";
cout<<"2. Load gamen";
cout<<"3. Play multiplayern";
cout<<"4. Exitn";
cout<<"Selection: ";
cin>> input;
switch ( input ) {
case 1: // Note the colon, not a semicolon
playgame();
break;
case 2: // Note the colon, not a semicolon
loadgame();
break;
case 3: // Note the colon, not a semicolon
playmultiplayer();
break;
case 4: // Note the colon, not a semicolon
cout<<"Thank you for playing!n";
break;
default: // Note the colon, not a semicolon
cout<<"Error, bad input, quittingn";
break;
}
cin.get();
}</iostream>

7. What is switch case in C++ Syntax?

Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char). The basic format for using switch case is outlined below. The value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program from that point.
switch ( <variable> ) {
case this-value:
Code to execute if <variable> == this-value
break;
case that-value:
Code to execute if <variable> == that-value
break;
...
default:
Code to execute if <variable> does not equal the value following any of the cases
break;
}</variable></variable></variable></variable>

8. How to defines the function in C++?

When the programmer actually defines the function, it will begin with the prototype, minus the semi-colon. Then there should always be a block with the code that the function is to execute, just as you would write it for the main function. Any of the arguments passed to the function can be used as if they were declared in the block. Finally, end it all with a cherry and a closing brace. Okay, maybe not a cherry.
Let's look at an example program:
#include <iostream>

using namespace std;

int mult ( int x, int y );

int main()
{
int x;
int y;

cout<<"Please input two numbers to be multiplied: ";
cin>> x >> y;
cin.ignore();
cout<<"The product of your two numbers is "<< mult ( x, y ) <<"n";
cin.get();
}

int mult ( int x, int y )
{
return x * y;
}</iostream>

9. What is functions Syntax in C++?

Functions that a programmer writes will generally require a prototype. Just like a blueprint, the prototype tells the compiler what the function will return, what the function will be called, as well as what arguments the function can be passed. When I say that the function returns a value, I mean that the function can be used in the same manner as a variable would be. For example, a variable can be set equal to a function that returns a value between zero and four.

For example:
#include <cstdlib> // Include rand()

using namespace std; // Make rand() visible

int a = rand(); // rand is a standard function that all compilers have</cstdlib>

10. What is do..while loops structure?

DO..WHILE loops are useful for things that want to loop at least once. The structure is
do {
} while ( condition );

Download Interview PDF