Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews C Plus Plus Language Interviews:C++ Access ControlC++ COM ActiveXC++ ConstructorsC++ ContainersC++ Exception HandlingC++ FriendC++ InheritanceC++ Inline FunctionC++ New And DeleteC++ Operator OverloadingC++ Pointers & FunctionsC++ ProgrammerC++ ReferencesC++ Static DataC++ SyntaxC++ TemplateC++ Type CheckingC++ Virtual Functions
Copyright © 2018. All Rights Reserved
C++ Syntax Interview Question:
What is prototype for that C string function?
Submitted by: MuhammadThe 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>
Submitted by: Muhammad
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>
Submitted by: Muhammad
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.