|
What is the use of friend function?
PHP Interview Questions and Answers
(Continued from previous question...)
What is the use of friend function?
Friend functions
Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one
class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class
that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves
members of that class.
A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that
class attached by the double colon syntax, a global function or member function of another class provides the match.
class mylinkage
{
private:
mylinkage * prev;
mylinkage * next;
protected:
friend void set_prev(mylinkage* L, mylinkage* N);
void set_next(mylinkage* L);
public:
mylinkage * succ();
mylinkage * pred();
mylinkage();
};
void mylinkage::set_next(mylinkage* L) { next = L; }
void set_prev(mylinkage * L, mylinkage * N ) { N->prev = L; }
Friends in other classes
It is possible to specify a member function of another class as a friend as follows:
class C
{
friend int B::f1();
};
class B
{
int f1();
};
It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.
class A
{
friend class B;
};
Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when
using the operator overloading features of C++. We will return to it when we look at overloading.
(Continued on next question...)
Other Interview Questions
- What's PHP
- What Is a Session?
- What is meant by PEAR in php?
- How can we know the number of days between two given dates using PHP?
- How can we repair a MySQL table?
- What is the difference between $message and $$message?
- What Is a Persistent Cookie?
- What does a special set of tags do in PHP?
- How do you define a constant?
- How To Write the FORM Tag Correctly for Uploading Files?
- What are the differences between require and include, include_once?
- What is meant by urlencode and urldecode?
- How To Get the Uploaded File Information in the Receiving Script?
- What is the difference between mysql_fetch_object and mysql_fetch_array?
- How can I execute a PHP script using command line?
- I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?
- Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?
- What are the different tables present in MySQL? Which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10))?
- How To Create a Table?
- How can we encrypt the username and password using PHP?
- How do you pass a variable by value?
- WHAT IS THE FUNCTIONALITY OF THE FUNCTIONS STRSTR() AND STRISTR()?
- When are you supposed to use endif to end the conditional statement?
- How can we send mail using JavaScript?
- What is the functionality of the function strstr and stristr?
- What is the difference between ereg_replace() and eregi_replace()?
- How do I find out the number of parameters passed into function9. ?
- What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain?
- If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b?
- Write a query for the following question
- How To Protect Special Characters in Query String?
- Are objects passed by value or by reference?
- What are the differences between DROP a table and TRUNCATE a table?
- What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods?
- How do you call a constructor for a parent class?
- WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?
- What’s the special meaning of __sleep and __wakeup?
- How can we submit a form without a submit button?
- Why doesn’t the following code print the newline properly? <?php $str = ‘Hello, there.\nHow are you?\nThanks for visiting fyicenter’; print $str; ?>
- Would you initialize your strings with single quotes or double quotes?
- How can we extract string 'abc.com ' from a string http://info@abc.com using regular expression of php?
- What is the difference between the functions unlink and unset?
- How come the code works, but doesn’t for two-dimensional array of mine?
- How can we register the variables into a session?
- What is the difference between characters \023 and \x23?
- With a heredoc syntax, do I get variable substitution inside the heredoc contents?
- How can we submit form without a submit button?
- How can we create a database using PHP and mysql?
- How many ways we can retrieve the date in result set of mysql using php?
- Can we use include ("abc.php") two times in a php page "makeit.php"?
- For printing out strings, there are echo, print and printf. Explain the differences.
- I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP?
- What’s the output of the ucwords function in this example?
- How can we extract string "abc.com" from a string "mailto:info@abc.com?subject=Feedback" using regular expression of PHP?
- So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?
- How can we destroy the session, how can we unset the variable of a session?
- What are the different functions in sorting an array?
- How can we know the count/number of elements of an array?
- How many ways we can pass the variable through the navigation between the pages?
- What is the maximum length of a table name, a database name, or a field name in MySQL?
- How many values can the SET function of MySQL take?
- What are the other commands to know the structure of a table using MySQL commands except EXPLAIN command?
- How can we find the number of rows in a table using MySQL?
- What’s the difference between md5(), crc32() and sha1() crypto on PHP?
- How can we find the number of rows in a result set using PHP?
- How many ways we can we find the current date using MySQL?
- Give the syntax of GRANT commands?
- Give the syntax of REVOKE commands?
- Answer the questions with the following assumption
- What is the difference between CHAR and VARCHAR data types?
- Will comparison of string "10" and integer 11 work in PHP?
- What is the functionality of MD5 function in PHP?
- How can I load data from a text file into a table?
- How can we know the number of days between two given dates using MySQL?
- How can we change the name of a column of a table?
- How can we change the data type of a column of a table?
- What is the difference between GROUP BY and ORDER BY in SQL?
- What is meant by MIME?
- How can we know that a session is started or not?
- What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
- If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?
- What are the MySQL database files stored in system ?
- What is the difference between PHP4 and PHP5?
- Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?
- What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
- What is meant by nl2br()?
- How can we encrypt and decrypt a data presented in a table using MySQL?
- How can I retrieve values from one database server and store them in other database server using PHP?
- WHO IS THE FATHER OF PHP AND WHAT IS THE CURRENT VERSION OF PHP AND MYSQL?
- IN HOW MANY WAYS WE CAN RETRIEVE DATA IN THE RESULT SET OF MYSQL USING PHP?
- What are the functions for IMAP?
- What are encryption functions in PHP?
- What is the difference between htmlentities() and htmlspecialchars()?
- What is the functionality of the function htmlentities?
- How can we get the properties (size, type, width, height) of an image using php image functions?
- How can we increase the execution time of a php script?
- HOW CAN WE TAKE A BACKUP OF A MYSQL TABLE AND HOW CAN WE RESTORE IT?
- How to set cookies?
- How to reset/destroy a cookie
- WHAT TYPES OF IMAGES THAT PHP SUPPORTS?
- CHECK IF A VARIABLE IS AN INTEGER IN JAVASCRIPT
- Tools used for drawing ER diagrams.
- How can I know that a variable is a number or not using a JavaScript?
- How can we submit from without a submit button?
- How many ways can we get the value of current session id?
- How can we destroy the cookie?
- What are the current versions of Apache, PHP, and MySQL?
- What are the reasons for selecting LAMP (Linux, Apache, MySQL, Php) instead of combination of other software programs, servers and operating systems?
- What are the features and advantages of OBJECT ORIENTED PROGRAMMING?
- What is the use of friend function?
- How can we get second of the current time using date function?
- What is the maximum size of a file that can be uploaded using PHP and how can we change this?
- How can I make a script that can be bilingual (supports English, German)?
- What are the difference between abstract class and interface?
- What are the advantages of stored procedures, triggers, indexes?
- What is maximum size of a database in mysql?
- Explain normalization concept?
- What’s the difference between accessing a class method via -> and via ::?
- What are the advantages and disadvantages of CASCADE STYLE SHEETS?
- What type of inheritance that php supports?
- How can increase the performance of MySQL select query?
- How can we change the name of a column of a table?
- When you want to show some part of a text displayed on an HTML page in red font color? What different possibilities are there to do this? What are the advantages/disadvantages of these methods?
- When viewing an HTML page in a Browser, the Browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?
- What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?
- Please give a regular expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag.
- How can I use the COM components in php?
- How many ways we can give the output to a browser?
- What is the default session time in php and how can I change it?
- What changes I have to do in php.ini file for file uploading?
- How can I set a cron and how can I execute it in Unix, Linux, and windows?
- Steps for the payment gateway processing?
- How many ways I can redirect a PHP page?
- List out different arguments in PHP header function?
- What type of headers have to be added in the mail function to attach a file?
- How to store the uploaded file to the final location?
- What is the difference between Reply-to and Return-path in the headers of a mail function?
- Explain about Type Juggling in php?
- How can I embed a java programme in php file and what changes have to be done in php.ini file?
- How To Turn On the Session Support?
- Explain the ternary conditional operator in PHP?
- What’s the difference between include and require?
- How many ways can we get the value of current session id?
- How can we destroy the cookie?
- How To Read the Entire File into a Single String?
|