What is the main difference between pointer and delegate with examples?,Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher
What is the main difference between pointer and delegate with examples?

The difference between pointer and delegate:-
Delegate:-A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked. Unlike function pointers in C or C++, delegates are object-oriented, type-safe, and secure. 
   using System;
 delegate void MyDelegate(string s);
 class MyClass
public static void Hello(string s)
 Console.WriteLine("  Hello, {0}!", s);
public static void Goodbye(string s)
Console.WriteLine("  Goodbye, {0}!", s);
public static void Main()
MyDelegate a, b, c, d;
a = new MyDelegate(Hello);
b = new MyDelegate(Goodbye);
 c = a + b;   // Compose two delegates to make another
d = c - a;   // Remove a from the composed delegate
Console.WriteLine("Invoking delegate a:");
 Console.WriteLine("Invoking delegate b:");
Console.WriteLine("Invoking delegate c:");
 Console.WriteLine("Invoking delegate d:");
Invoking delegate a:
  Hello, A!
Invoking delegate b:
  Goodbye, B!
Invoking delegate c:
  Hello, C!
  Goodbye, C!
Invoking delegate d:
  Goodbye, D!
Code Discussion
Pointer:-C# statements execute in either a safe or an unsafe context. Safe context is the default, but any code using pointers requires unsafe context.
unsafe:-   Specifies unsafe context. 
Once you have a pointer to a variable, you must ensure that the variable isn't moved in memory by the garbage collector.
pointer holds reference to a variable or pointer is a variable which holds the address of another variable.
         using System;
class UnsafeTest 
   // unsafe method: takes pointer to int
   unsafe static void SquarePtrParam (int* p) 
      *p *= *p;

   public static void Main() 
      int i = 5;
      // unsafe statement for address-of operator
      unsafe SquarePtrParam (&i);
      Console.WriteLine (i);

More interview questions and answers

Is it mandatory to implement all the methods which are there in abstract class if we inherit that abstract class?

What is the difference between const and static read-only?

How to fill datalist usinf XML file and how to bind it,code behind language is c# ?

What is advantase of serialization?

How we handle sql exceptions?

What is the class that handles SqlServer exceptions?

What is indexer?

where indexer is used ?

Can we inherit the java class in C# class?If Yes then how?

Every statement in C# must end with?

The C# code files have an extension ?

How you can compile a C# program using command promt?

ASP.NET web pages can be programmed in C#?

All the .NET languages have the following in common?

IL code compiles to ?

Which is the first level of compilation in the .NET languages?

What is IL?

What is CTS?

What is the namespace used for Reflection?

To access attributes, the waht is used?

List all collections in C#.

How you can write Unsafe code in C# and in which block?

Which method is used to force the garbage collector?

Each process in a 32 bit Windows environment has the what amount of virtual memory will available?

What is correct syntax for defining a delegate?

What is syntax of inherit a class?

How do you deploy an assembly?

How namespace is used for globalization?

How does a running application communicate or share data with other application running in different application domains?

What are difference between shadow and override?

We have an event handler called MyEvent and we want to link the click event of control, MyButton, to use MyEvent, what is the code that will like them together?

Which debugging window allows you to see the methods called in the order they were called?

The auto,local ,watch

What is wrapper class? Is it available in c#?

What is protected internal class in C# ?

Which keyword is used of specify a class that cannot inherit by other class?

Can we create the instance for abstract classes?

Can we use Friend Classes or functions in C#?

How we can use inheritance and polymorphisms in c# programming?

How to find exceptions in database?Give examples .

How can objects be late bound in .NET?

Where we can use DLL made in C#.Net?

What Datatypes does the RangeValidator Control support?

Constructor is the method which is implicitly created when ever a class is instantiated. Why?

Why multiple Inheritance is not possible in C#?

Why strings are immutable?

This is a Regular expression built for parsing string in vb.net and passed to Regex class. Dim r As Regex = New Regex(",(?=([^""]*""[^""]*"")*(?![^""]*""))") What is C# equivalent for this regular exp

How to convert ocx into DLL ?

What is the main difference between pointer and delegate with examples?

What is object pooling ?

How do i read the information from web.config file?

What is the default Function arguments?

What is XML Schema?

How can we check whether a dataset is empty or not in C#.net

Is it possible to inherit a class that has only private constructor?

How do you choose 1 entry point when C# project has more Main( ) method?

What is C# reserved keyword ?Give List.

Sealed class can be inherited ?Yes/No

It is not permitted to declare modifier on the members in an interface definition?

How Interface members can be declare ?

Which method is implicitly called when an object is created ?

Constructors can not be static?Yes/NO

Which preprocessor directive are used to mark that contain block of code is to be treated as a single block?

How are the attributes specified in C# ?

For performing repeated modification on string which class is preferred?

In order to use stringbuilder in our class we need to refer??

Gives the a member of stringbuilder.

Which method is actually called ultimately when Console.WriteLine( ) is invoked?

What happens when you create an arraylist as ArrayList Arr=new ArrayList()?

What is the output of Vectors.RemoveAt(1)?

GetEnumerator( ) of Ienumerable interface returns ?

How do you add objects to hashtable in c#?

If A.equals(B) is true then A.getHashcode & B.getHashCode must always return same hash code in c#?

The assembly class is defined in??

What is the first step to do anything with assembly??

How do you load assembly to running process ??

Assemblies cannot be loaded side by side??

Where Application Isolation is assured using ??

Where does the version dependencies recorded ?

How do you refer parent classes in C# ?

Which attribute you generally find on top of main method ??

How do you make a class not instantiable??

In a multilevel hierarchy how are the constructors are called ??

Which utility is used to create resource file ??

What is the extension of a resource file??

A shared assembly must have a strong name to uniquely identify the assembly??

Where Public policy applies in C#??

Stream object can not be initialized?T/F

What is base class of stream??

Which class use to Read/Write data to memory in C#

To Configure .Net for JIT activation what do you do ??

Which method is used by COM+ to ascertain whether class can be pooled??

How do you import Activex component in to .NET ??

.Net Remoting doesn't allow creating stateless & stateful Remote objects?Explain.

Windows services created by C# app run only?Yes/No?How?

The C# keyword int maps to which .NET type

What is an indexer in C#

How to implement multiple inheritence in C# ?

What is the use of fixed statement?

Can static methods be overridable?

R4R provides free online tutolrails ,examples for Freshers and experts .We cover core java, tutorials, spring, Hibernate, python, struts, struts 2,c language, spring boot,PHP,MYSQL,C#,ASP.NET,WPF,WCF,Photoshop , JSP, programming, example, Interview questions and answer