C# is a programming language that has been rapidly growing and is being intensively used. It can be used for a number of operating systems such as Windows, iOS, Android, etc. C# is a simple, modern and object-oriented language. Some of the particular syntax used in C# are semicolons, curly brackets, variables (two variables are assigned with the help of an equal sign) and square brackets.
- C Language Interview Questions And Answers For Freshers Pdf Free Download
- Interview Questions And Answers Pdf
- Interview Questions To Ask Employer
It has a number of advantages and is very user-friendly which makes it one of the most used programming languages in the IT firms. Thus, a number of multinational companies these days are looking for individuals to help them grow in their organization. Thus, such companies ask a diverse range of C# interview questions to not only freshers but also experienced individuals wishing to display their talent and knowledge in the field of C# programming. Here are some important C# interview questions that will not only give you a basic idea of the field but also help to clear interview on advanced c# questions.
Download C# Interview Questions PDFBelow are the list of Best C# Interview Questions and Answers
1) What is C#?
The application process can be extremely time-consuming, so when you finally land an interview, it's normal to stress about providing the best possible answers to common interview questions. Most likely, that will mean being able to talk about your prior experience and how it's prepared you for the role. 110 Exam and interview questions on WIN32, MFC and C/C under Windows for developers/learners. Click on the link to get the detailed explanations. One you visit any answer you can navigate through next and previous link to jump from one answer to another. You can also select index to. C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c.
C# is a programming language which is object-oriented developed by Microsoft. C# is designed and fabricated for a Common Language Infrastructure that constitutes an executable code and runtime, which allows the usage of different high – end languages for different platforms and design.
2) Define a class and an object.
A class is an example of properties and techniques that utilize and characterize a continuous substance. It can represent information that unites each illustration into a single component. An Object is a sub-occurrence of a Class. In fact, it is only a square of memory assigned that can be put away as Variables, Array or a Collection.
3) List the fundamental OOP concepts.
The fundamentals of an OOP concept are:
- Encapsulation: The internal portrayal of the object is concealed from the predators view from the definition of the object. Only the information that is required can be retrieved whereas the rest of the data is kept hidden.
- Abstraction: It is a procedure of distinguishing the basic conduct and information of an object and disregarding the insignificant details.
- Inheritance: It is the ability to make new classes from a different class. It is carried out by retrieving, altering and broadening the conduct of the objects in the parent class.
- Polymorphism: It implies one name with numerous structures. It is accomplished by having numerous techniques with a similar name with dissimilar usage.
4) Enlist the different types of classes in C#.
The four types of classes in C# are:
- Partial class: Allows its associates to be separated or shared with different.cs documents. It is indicated by the keyword 'Partial'.
- Sealed class: It is a class, which cannot be acquired. To get to the member from a fixed class, we have to make the object of the class. It is indicated by the keyword 'Sealed'.
- Abstract class: It is a class where the object cannot be instantiated. This class can be acquired; however, it should have at least one technique. It is indicated by the keyword 'conceptual'.
- Static class: It is a class, which does not permit legacy. The members of the class are additionally static. It is indicated by the keyword 'static'. This keyword advises the compiler to check for any unplanned instances in the static class.
5) List the steps in code compilation in C#.
The four steps involved in code compilation in C# are:
C Language Interview Questions And Answers For Freshers Pdf Free Download
- Compilation of the source code by a C# compiler into the code.
- Compilation of the newly generated code into the assemblies.
- Loading of the common language runtime.
- Execution of the assembly by the common language runtime.
6) Explain the process of Abstraction with an example
Abstraction is the process that is used to highlight an important feature of the class that can hide the irrelevant information.
For example – A driver of a car ought to know the details of the car such as its brand name, color, gear, brake, etc. However, the information that is not of importance to him are details of the car such as the exhaust system, internal engine, etc. Thus, the process of abstraction helps in identification and extraction of the information that is relevant to the user and not needed from the outside world. A number of parameters such as with the usage of 'private' keyword can help in hiding internal information.
7) Explain the process of Polymorphism with an example.
Polymorphism is the process when the same method is applied using different implementation techniques. Polymorphism is of two types:
Compile time polymorphism: when an operator is overloaded.
Runtime polymorphism: when an operator is overridden
For example – If a particular class has Void Add (), then polymorphism can be accomplished by the overload technique, then the Void Add() becomes Void Add(int a, int b) and Void Add(int add).
8) Describe the process of 'exception handling implementation' in C#
Exception handling can be implemented in C# using the following keywords:
- try
- catch
- finally
- throw
9) Give some examples of commonly used I/O classes
Some examples of I/O classes are:
- File: used in manipulating a file
- StreamWriter: used for writing different characters into a stream
- StreamReader: used for reading characters off a stream
- StringWriter: used for reading from a string buffer
- StringReader: used for writing into a string buffer
- Path: used for execution of different operations that are related to a path data
10) What are some characteristics of an array?
Some characteristics of an array class are Length, IsFixedSize, IsReadOnly.
11) Write a code using Regular expression
12) List some of the basic string operation
Some of the basic string operations are:
- concatenate
- modify
- compare
- search
13) What is a generic class?
A generic class is utilized to generate classes or objects that do not have a precise type of data. However, the data type can be assigned anytime while using the program.
14) Enlist some of the properties of a thread class.
Some of the properties of a thread class are:
- IsAlive
- Name
- Priority
- IsBackground
- ThreadState
15) List the different stages of a thread.
The different stages of a thread are:
- Unstarted
- Running
- WaitSleepJoin
- Suspended
- Aborted
- Stopped
16) Explain the different types of delegates used in C#.
Different types of delegates used in C# are:
- Single Delegate: a delegate that can utilize only a single method
- Multicast Delegate: a delegate that can utilize multiple methods
Ads Free Download our Android app for C# Interview Questions (Interview Mocks )
Got a Questions? Share with us
Features of C#
- Simple
- Modern
- Object Oriented
- Type Safe
- Scalable
- Updatable
- Portability
- Metaprogramming
- Memory access
- Compatibility with other programming languages
Pros of C#
- It is an object-oriented language
- Has high productivity
- It is very versatile
- It is one of the most powerful programming languages
Cons of C#
- Not easy for newcomers to use
- It is a case-sensitive language
- Less efficient in comparison to C+ and C++
Also Read Related C# Interview Questions
Active Directory Interview QuestionsActivex Interview questionsWPF interview questionsWCF Interview QuestionsLINQ interview questionsMVC interview questionsASP.NET Interview QuestionsVB.Net Interview QuestionsADO.Net Interview QuestionsPowerShell Interview Questions- Common Interview Questions
- Python Flask Interview Questions
- NoSQL interview questions
- JQuery Interview Questions
- C programming interview questions
- AngularJS Interview Questions
- Node JS Interview Questions with Express
- JavaScript Interview Questions
- Core Java interview questions
- HTML Interview Questions
- Laravel interview questions
- Wordpress Interview Questions
- PHP Interview Questions
- Details
- Last Updated: Tuesday, 10 January 2017 Hits: 55806
1) What will be the output of printf('%d')?
The first argument which contains strings to be printed or format specifiers is mandatory. Other than that, the arguments are optional.So, in case of only %d used without any variable in printf, the compiler may generate warning but will not cause any error. In this case, the correct offset based on %d is calculated by compiler but as the actual data variable is not present in that calculated location of memory, the printf will fetch integer size value and print whatever is there (which is garbage value to us).
2) What is the return values of printf and scanf?The printf function upon successful return, returns the number of characters printed in output device. So, printf('A') will return 1. The scanf function returns the number of input items successfully matched and assigned, which can be fewer than the format specifiers provided. It can also return zero in case of early matching failure.
3) How to free a block of memory previously allocated without using free?
If the pointer holding that memory address is passed to realloc with size argument as zero (like realloc(ptr, 0)) the the memory will be released.
4) How can you print a string containing '%' in printf?
Ea sports cricket game 2015. There are no escape sequence provided for '%' in C. To print '%' one should use '%%', like -
5) What is use of %n in printf()?
Ans: According to man page 'the number of characters written so far is stored into the integer. indicated by the int * (or variant) pointer argument.'. Meaning if we use it in printf, it will get the number of characters already written until %n is encountered and this number will stored in the variable provided. The variable must be an integer pointer.
Above program will print 'Hello world 5 ' as Hello is 5 letter.
6) Swap two variables without using any control statement ?
We can swap variable using 2 methods. First method is as given below
Second method to swap variables is given below
7) Consider the two structures Struct A and Struct B given below. What will be size of these structures?
struct A
{
unsigned char c1 : 3;
unsigned char c2 : 4;
unsigned char c3 : 1;
}a;
struct A
{
unsigned char c1 : 3;
unsigned char : 0;
unsigned char c2 : 4;
unsigned char c3 : 1;
}a;
The size of the structures will be 1 and 2. In case of first structure, the members will be assigned a byte as follows -
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
c3 | c2 | c2 | c2 | c2 | c1 | c1 | c1 |
But in case of second structure -
8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
c3 | c2 | c2 | c2 | c2 | c1 | c1 | c1 |
The :0 field (0 width bit field) forces the next bit width member assignment to start from the next nibble. By doing so, the c3 variable will be assigned a bit in the next byte, resulting the size of the structure to 2.
8) How to call a function before main()?
To call a function pragma startup directive should be used. Pragma startup can be used like this -
The output of the above program will be -
But this pragma directive is compiler dependent. Gcc does not support this. Simply tv xbox one. So, it will ignore the startup directive and will produce no error. But the output in that case will be -
4) Enlist the different types of classes in C#.
The four types of classes in C# are:
- Partial class: Allows its associates to be separated or shared with different.cs documents. It is indicated by the keyword 'Partial'.
- Sealed class: It is a class, which cannot be acquired. To get to the member from a fixed class, we have to make the object of the class. It is indicated by the keyword 'Sealed'.
- Abstract class: It is a class where the object cannot be instantiated. This class can be acquired; however, it should have at least one technique. It is indicated by the keyword 'conceptual'.
- Static class: It is a class, which does not permit legacy. The members of the class are additionally static. It is indicated by the keyword 'static'. This keyword advises the compiler to check for any unplanned instances in the static class.
5) List the steps in code compilation in C#.
The four steps involved in code compilation in C# are:
C Language Interview Questions And Answers For Freshers Pdf Free Download
- Compilation of the source code by a C# compiler into the code.
- Compilation of the newly generated code into the assemblies.
- Loading of the common language runtime.
- Execution of the assembly by the common language runtime.
6) Explain the process of Abstraction with an example
Abstraction is the process that is used to highlight an important feature of the class that can hide the irrelevant information.
For example – A driver of a car ought to know the details of the car such as its brand name, color, gear, brake, etc. However, the information that is not of importance to him are details of the car such as the exhaust system, internal engine, etc. Thus, the process of abstraction helps in identification and extraction of the information that is relevant to the user and not needed from the outside world. A number of parameters such as with the usage of 'private' keyword can help in hiding internal information.
7) Explain the process of Polymorphism with an example.
Polymorphism is the process when the same method is applied using different implementation techniques. Polymorphism is of two types:
Compile time polymorphism: when an operator is overloaded.
Runtime polymorphism: when an operator is overridden
For example – If a particular class has Void Add (), then polymorphism can be accomplished by the overload technique, then the Void Add() becomes Void Add(int a, int b) and Void Add(int add).
8) Describe the process of 'exception handling implementation' in C#
Exception handling can be implemented in C# using the following keywords:
- try
- catch
- finally
- throw
9) Give some examples of commonly used I/O classes
Some examples of I/O classes are:
- File: used in manipulating a file
- StreamWriter: used for writing different characters into a stream
- StreamReader: used for reading characters off a stream
- StringWriter: used for reading from a string buffer
- StringReader: used for writing into a string buffer
- Path: used for execution of different operations that are related to a path data
10) What are some characteristics of an array?
Some characteristics of an array class are Length, IsFixedSize, IsReadOnly.
11) Write a code using Regular expression
12) List some of the basic string operation
Some of the basic string operations are:
- concatenate
- modify
- compare
- search
13) What is a generic class?
A generic class is utilized to generate classes or objects that do not have a precise type of data. However, the data type can be assigned anytime while using the program.
14) Enlist some of the properties of a thread class.
Some of the properties of a thread class are:
- IsAlive
- Name
- Priority
- IsBackground
- ThreadState
15) List the different stages of a thread.
The different stages of a thread are:
- Unstarted
- Running
- WaitSleepJoin
- Suspended
- Aborted
- Stopped
16) Explain the different types of delegates used in C#.
Different types of delegates used in C# are:
- Single Delegate: a delegate that can utilize only a single method
- Multicast Delegate: a delegate that can utilize multiple methods
Ads Free Download our Android app for C# Interview Questions (Interview Mocks )
Got a Questions? Share with us
Features of C#
- Simple
- Modern
- Object Oriented
- Type Safe
- Scalable
- Updatable
- Portability
- Metaprogramming
- Memory access
- Compatibility with other programming languages
Pros of C#
- It is an object-oriented language
- Has high productivity
- It is very versatile
- It is one of the most powerful programming languages
Cons of C#
- Not easy for newcomers to use
- It is a case-sensitive language
- Less efficient in comparison to C+ and C++
Also Read Related C# Interview Questions
Active Directory Interview QuestionsActivex Interview questionsWPF interview questionsWCF Interview QuestionsLINQ interview questionsMVC interview questionsASP.NET Interview QuestionsVB.Net Interview QuestionsADO.Net Interview QuestionsPowerShell Interview Questions- Common Interview Questions
- Python Flask Interview Questions
- NoSQL interview questions
- JQuery Interview Questions
- C programming interview questions
- AngularJS Interview Questions
- Node JS Interview Questions with Express
- JavaScript Interview Questions
- Core Java interview questions
- HTML Interview Questions
- Laravel interview questions
- Wordpress Interview Questions
- PHP Interview Questions
- Details
- Last Updated: Tuesday, 10 January 2017 Hits: 55806
1) What will be the output of printf('%d')?
The first argument which contains strings to be printed or format specifiers is mandatory. Other than that, the arguments are optional.So, in case of only %d used without any variable in printf, the compiler may generate warning but will not cause any error. In this case, the correct offset based on %d is calculated by compiler but as the actual data variable is not present in that calculated location of memory, the printf will fetch integer size value and print whatever is there (which is garbage value to us).
2) What is the return values of printf and scanf?The printf function upon successful return, returns the number of characters printed in output device. So, printf('A') will return 1. The scanf function returns the number of input items successfully matched and assigned, which can be fewer than the format specifiers provided. It can also return zero in case of early matching failure.
3) How to free a block of memory previously allocated without using free?
If the pointer holding that memory address is passed to realloc with size argument as zero (like realloc(ptr, 0)) the the memory will be released.
4) How can you print a string containing '%' in printf?
Ea sports cricket game 2015. There are no escape sequence provided for '%' in C. To print '%' one should use '%%', like -
5) What is use of %n in printf()?
Ans: According to man page 'the number of characters written so far is stored into the integer. indicated by the int * (or variant) pointer argument.'. Meaning if we use it in printf, it will get the number of characters already written until %n is encountered and this number will stored in the variable provided. The variable must be an integer pointer.
Above program will print 'Hello world 5 ' as Hello is 5 letter.
6) Swap two variables without using any control statement ?
We can swap variable using 2 methods. First method is as given below
Second method to swap variables is given below
7) Consider the two structures Struct A and Struct B given below. What will be size of these structures?
struct A
{
unsigned char c1 : 3;
unsigned char c2 : 4;
unsigned char c3 : 1;
}a;
struct A
{
unsigned char c1 : 3;
unsigned char : 0;
unsigned char c2 : 4;
unsigned char c3 : 1;
}a;
The size of the structures will be 1 and 2. In case of first structure, the members will be assigned a byte as follows -
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
c3 | c2 | c2 | c2 | c2 | c1 | c1 | c1 |
But in case of second structure -
8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
c3 | c2 | c2 | c2 | c2 | c1 | c1 | c1 |
The :0 field (0 width bit field) forces the next bit width member assignment to start from the next nibble. By doing so, the c3 variable will be assigned a bit in the next byte, resulting the size of the structure to 2.
8) How to call a function before main()?
To call a function pragma startup directive should be used. Pragma startup can be used like this -
The output of the above program will be -
But this pragma directive is compiler dependent. Gcc does not support this. Simply tv xbox one. So, it will ignore the startup directive and will produce no error. But the output in that case will be -
9) What is rvalue and lvalue?
You can think lvalue as a left side operant in an assignment and rvalue is the right. Also, you can remember lavlue as location. So, the lvalue means a location where you can store any value. Say, for statement i = 20, the value 20 is to be stored in the location or address of the variable i. 20 here is rvalue. Then the 20 = I, statement is not valid. It will result in compilation error 'lvalue required' as 20 does not represent any location.
10)How to pack a structure?
We can pack any structure using __attribute__((__packed__)) in gcc. Example -
We can also use, pragma pack like this -
In both cases the size of the structure will be 5. But remember, the pragma pack and the other method mentioned, both are compiler dependent.
11) How to convert a string to integer value?
We can convert a string to integer in two ways. Method 1:
Method 2:
12) Print the output of the following switch case program?
Output of this program will be 3. The position of the default is before case 1. So, even if there is no break after case 3, the execution will just exit switch case and it will not go to default case.
Interview Questions And Answers Pdf
13) How to prevent same header file getting included multiple times?
We can use ifndef and define preprocessors. Say the header file is hdrfile.h, then we can write the header file like -
Interview Questions To Ask Employer
The ifndef will check whether macro HDRFILE_H_ is defined or not. If it is not defined, it will define the macro. From next time onward the statements inside ifndef will not be included.
14) Which is better #define or enum?
- Enum values can be automatically generated by compiler if we let it. But all the define values are to be mentioned specifically.
- Macro is preprocessor, so unlike enum which is a compile time entity, source code has no idea about these macros. So, the enum is better if we use a debugger to debug the code.
- If we use enum values in a switch and the default case is missing, some compiler will give a warning.
- Enum always makes identifiers of type int. But the macro let us choose between different integral types.
- Macro does not specifically maintain scope restriction unlike enum. For example -
Above program will print -
15) Print the output of this pointer program?
The program will crash. The pointer p points to string 'Pointers'. But the string in constant and C will not allow to change its values. Forcibly doing so, like we did it, will cause crash of the program.
- Prev
- 1