C# Questions Answers - C# basic syntax (PartI)


C# Questions Answers-C# basic syntax(PartI)

1. What would be printed from the following C++ program?

#include<iostream>
#include<conio.h>
using namespace std;

void printinfo(int);
void printinfo(string);

 struct student //define structure student
     {
       //variables
        int id;
        string name;

      };

   int main()
   {

       student st; //structure object
       st.id = 100; //assign 100 to student id
       st.name = "Sok";//assign Sok to student name
       //output student information
       printinfo(st.id);
       printinfo(st.name);

       getch();
       return 0;

    }

   void printinfo(int id)
   {
     cout<<id<<"\n";
    }
   void printinfo(string name)
   {
      cout<<name<<"\n";
    }

 

 
Check answer 2. What would be printed from the following C++ program?
#include<iostream>
#include<conio.h>
using namespace std;


 struct Point
   {
     int x;
     int y;
    };

void makeTriangle(Point p[]);
    int main()
    {

      Point p[3];
      int i;
      makeTriangle(p);
      cout<<"The triangle consists of the following coordinates:\n";
      for(i=0 ;i<3;i++)
           cout<<"("<<p[i].x<<","<<p[i].y<<")"<<"\n";     
     
      getch();
      return 0;
    }

   void makeTriangle(Point p[]){
      p[0].x = 200;
      p[0].y = 20;
      p[1].x = 150;
      p[1].y = 100;
      p[2].x = 300;
      p[2].y = 100;

      }



   Check answer 3. What would be printed from the following C++ program?
#include<iostream>
#include<conio.h>
using namespace std;


struct Fract
     {
        int nomi;
        int deno;
     
      };

Fract sum(Fract,Fract);

   int main()
    {


     Fract f1={1, 2};/* 1/2 */
     Fract f2 ={2, 5};/* 2/5 */
     Fract result = sum(f1, f2);//sum the fractions
     cout<<"Result="<<result.nomi<<"/"<<result.deno;  //display the result


     getch();
     return 0;

    }

   Fract sum(Fract f1, Fract f2)
    {
     Fract result={(f1.nomi * f2.deno) + (f2.nomi * f1.deno), f1.deno * f2.deno};
     return result;

     }



  Check answer

Comments

KrishnaMohan comment

 KrishnaMohan

Nice question check this also for similar kind of c# interview questions
http://skillgun.com/csharp/interview-questions-and-answers


2014-06-05



    This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
    C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.