August 2021

Pass by Value And Pass by Address

There are two ways to pass arguments to a function — Pass by Value and Pass by Address. The major difference between Pass by Value and Pass by Address is in the pass by value copy of actual arguments is passed to respective formal arguments. While, in the call by reference, the location (address) of actual arguments is passed to formal arguments. Hence, any change made to formal arguments will also reflect in actual arguments. Pass by Value: A copy of actual arguments is passed to formal arguments of the called function, and any change made to the formal arguments in the called function does not affect the values of actual arguments in the calling function. Incall by value, actual arguments will remain safe they cannot be modified accidentally.  #include<stdio.h> void swap (int a, int b) {           int temp;           temp=a;           a=temp;           b=temp;           printf(“a=%d,b=%d”,a,b); } int main() {           int a=10,b=20;           swap(a,b);           printf(“a=%d\n,b=%d\n”,a,b); } output:           a=20,b=10(in function swap)           a=10,b=20(in main function) In the above program, a and b values are updated only in the function and not swap in the main function. Pass by Address: In Pass by address, the location (address) of actual arguments is passed to formal arguments of the called function. That means by accessing the addresses of actual arguments we can alter them within the called function. Alteration to actual arguments is possible within from called function. Therefore, the code must handle arguments carefully else you get unexpected results. #include<stdio.h> void swap (int *a,int *b) {           int temp;           temp=*a;           *a=temp;           *b=temp;           printf(“a=%d,b=%d”,*a,*b); } int main() {           int a=10,b=20;           swap(&a,&b);           printf(“a=%d\n,b=%d\n”,a,b); } output:           a=20,b=10(in function swap)           a=20,b=10(in main function) In the above program, a and b addresses are passed and in the function swap those addresses are received by the pointers updated values are reflected in the main function.

Pass by Value And Pass by Address Read More »

Macros vs Functions

Macros are preprocessed, meaning that all the macros would be executed before the compilation stage. However, functions are not preprocessed but compiled. Example of Macro: #include<stdio.h> #define  A 10 int main() {      printf(“%d”,A);      return 0; }  OUTPUT=10; Example of Function: #include<stdio.h> int A() {     return 10; } int main() {     printf(“%d”, A());     return 0; } OUTPUT=10; Now compile them using the command: GCC –E file_name.c This will give you the executable code as shown below: #include<stdio.h> #define  A 10 int main() {      printf(“%d”,A);      return 0; } #include<stdio.h> int A() {     return 10; } int main() {     printf(“%d”, A());     return 0; } The first program shows that the macros are preprocessed while functions are not. In macros, no type checking (incompatible operand, etc.) is done, and thus, the use of macros can lead to errors/side-effects in some cases. That is not the case with functions. Macros do not check for a compilation error. Macros are usually one-liners. However, they can consist of more than one line, and there are no such constraints in functions. The speed at which macros and functions differ. Macros are typically faster than functions as they don’t involve actual function call overhead. MACRO FUNCTION Macro is Preprocessed  Function is Compiled No Type Checking is done in Macro Type Checking is Done in Function Using Macro increases the code length Using Function keeps the code length unaffected Use of macro can lead to side effects at later stages Functions do not lead to any side effects in any case Speed of Execution using Macro is Faster Speed of Execution using Function is Slower Before Compilation, the macro name is replaced by macro value During function call, transfer of control takes place Macros are useful when small code is repeated many times Functions are useful when large code is to be written Macro does not check any Compile-Time Errors Function checks Compile-Time Errors

Macros vs Functions Read More »

Carbon Nanotube Field Effect Transistor

The present VLSI electronic systems rely on the Silicon MOS (metal oxide semiconductor) technology which advances will soon come to saturation. Carbon nanotubes represent an advancement in the materials technology with the potential for providing switching devices that may be faster and smaller than the present MOS devices. Carbon nanotubes are miniature tube structures with intriguing characteristics. The tube, in the normal untwisted state, conducts electricity. When twisted, the tube acts as a semiconductor.  This transistor is considered one of the greatest inventions of the twentieth century. It has helped to bring about both the information and computing age. One reason for success is its ability to decrease in size and increase in speed. This property is summarized in Moore’s law. It states that the transistor’s size will decrease exponentially while the speed will increase exponentially. Moore’s law has allowed the technology sector to progress and remain competitive. The physical barriers arise due to the continued shrinking of the current transistor used today, the Metal-Oxide Field Effect Transistor or MOSFET. As the size shrinks, the thickness of the insulators reduces. Insulators are used to electronically isolate parts of the transistor. With the thinner insulation, the carriers can quantum-mechanically tunnel across the insulation. The result is a short circuit allowing current to flow directly from the source to drain and then drain to the body. And even though the thin gate oxide, that separates the gate from the channel. In addition, doping becomes a problem since it relies on percentages. If the total amount of atoms gets very small, then a fractional dopant atom might be required, which of course, is impossible. In addition, economic problems arise from producing and maintaining the fabrication lines. One proposed solution is the use of carbon nanotubes instead of silicon to make the transistors. The construction and operation of CNFET are similar to the MOSFETs that we use today, thus giving them the name Carbon Nanotube Field-Effect Transistor or CNFET. Three of the most important characteristics of any transistor are speed, scalability, and power. Speed: The carbon nanotubes unique one-dimensional nature; can utilize ballistic transport. Ballistic transport means that the mean free path is longer than the path. Thus, the charge carriers do not collide, reducing resistance to negligible levels. The result is a capability to achieve speeds of Terahertz or more, compared to today’s processors that operate at 3 gigahertz. Scalability: A group in IBM discovered an interesting property of the CNFETs scalability. While the CNFETs improve with scaling, it is not conventional. They seem to follow the behaviour of Schottky barrier MOSFETs instead of regular MOSFETs. For this reason, the group at IBM feels that the CNFETs limits for scaling are unclear. However, they do note that, in a structured array, the CNFETs will produce enough gain and fan out for real-life applications. In addition to the CNFETs murky limits of scaling, it still will outperform silicon MOSFETs limits of scaling. Power: The same group at IBM compared some properties of the CNFET to both a high-performance silicon MOSFET and a newer MOSFET design that utilize Silicon-On-Insulator (SOI) technology. The results are displayed in table 1. Table 1: Comparison between MOSFET and CNT Circuit FET Delay (in pico second) Power (in micro watt) Inverter CMOS 16.58 9.81 CNT 3.78 0.25 2 Input NAND CMOS 24.32 20.67 CNT 5.98 0.69 2 Input NOR CMOS 39.26 22.13 CNT 6.49 0.48 One important difference is in I(OFF). The CNTFET has a drop of about 70% as compared to the conventional MOSFET. That emphasis on power being wasted while the transistor is off is greatly reduced. In addition, we notice that I(ON), or drive current, is larger than both technologies. In fact, it is three to four times larger. Normally, we would think that this is a bad thing. As our first instinct would mean higher power consumption. However, since the nanotube has ballistic conductance, it actually has a smaller resistance. Thus, the power consumption is the same if not smaller than the current MOSFET design. This is also supported by the two to four times increase in trans-conductance. The real big surprise is that the CNTFET is able to outperform both the current and newer technologies, despite the large gate length and gate oxide thickness. So naturally, when the CNFET design is optimized, the CNTFET will surely outperform the current technology. For these reasons, the CNTFET is a very strong contender to replace the current technology.

Carbon Nanotube Field Effect Transistor Read More »

C++ Friend function & Friend Class

If a function is defined as a friend function in C++, then the protected and private data of a class can be accessed using the function. By using the keyword, the friend compiler knows the given function is a friend function. For accessing the data, the declaration of a friend function should be done inside the body of a class, starting with the keyword friend. Declaration of friend function in C++ Class class_name { friend data_type function_name(argument/s); // syntax of friend function. }; In the above declaration, the friend function is preceded by the keyword friend. The function can be defined anywhere in the program like a normal C++ function. The function definition does not use either the keyword friend or scope resolution operator. Characteristics of a Friend function: C++ friend function Example Let’s see the simple example of the C++ friend function used to print the length of a box.             #include <iostream>             using namespace std;             class Box             {                         private:                         int length;             public:             Box() : length(0) {}             friend int printLength(Box); // friend function             };             int printLength(Box b)             {                         b.length + = 10;                         return b.length;             }             int main()             {                         Box b;                         cout  << “Length of box: “ << printLength(b) << endl;                         return 0;             } Output: Length of the box: 10 C++ Friend class A friend class can access both private and protected members of the class in which it has been declared as a friend. Let’s see a simple example of a friend class.             #include <iostream>             using namespace std;             class A             {                         int x =5;                         friend class B; // friend class             };             class B             {                         public:                         void display(A &a)                         {                                     cout << “value of x is : “ << a.x << endl;                             }             };             int main()             {                         A a;                         B b;                         b.display(a);                         return 0;             } Output: Value of x is: 5 In the above example, class B is declared as a friend inside the class A. Therefore, B is a friend of class A. Class B can access the private members of class A.

C++ Friend function & Friend Class Read More »

C++ Copy Constructor

A Copy constructor is an overloaded constructor used to declare and initialize an object from another object. Copy Constructor is of two types: Default Copy constructor: The compiler defines the default copy constructor. If the user defines no copy constructor, the compiler supplies its constructor. User-Defined constructor: The programmer defines the user-defined constructor. Syntax Of User-defined Copy Constructor: Class_name(const class_name &old_object); When Copy Constructor is called Copy Constructor is called in the following scenarios: Two types of copies are produced by the constructor: Shallow Copy #include <iostream>      using namespace std;       class Demo      {          int a;          int b;          int *p;          public:          Demo()          {              p=new int;          }          void setdata(int x,int y,int z)          {              a=x;              b=y;              *p=z;          }          void showdata()          {              std::cout << “value of a is : ” <<a<< std::endl;              std::cout << “value of b is : ” <<b<< std::endl;              std::cout << “value of *p is : ” <<*p<< std::endl;          }      };      int main()      {        Demo d1;        d1.setdata(4,5,7);        Demo d2 = d1;        d2.showdata();          return 0;      }  Demo d2 = d1; calls the default constructor defined by the compiler. The default constructor creates the exact copy or shallow copy of the existing object. Thus, the pointer p of both the objects point to the same memory location. Therefore, when the memory of a field is freed, the memory of another field is also automatically freed as both the fields point to the same memory location. This problem is solved by the user-defined constructor that creates the Deep copy. Deep copy Deep copy dynamically allocates the memory for the copy and then copies the actual value both the source and copy have distinct memory locations. In this way, both the source and the copy are distinct and will not share the same memory location. Deep copy requires us to write the user-defined constructor. #include <iostream>      using namespace std;      class Demo      {          public:          int a;          int b;          int *p;          Demo()          {              p=new int;          }          Demo(Demo &d)          {              a = d.a;              b = d.b;              p = new int;              *p = *(d.p);          }          void setdata(int x,int y,int z)          {              a=x;              b=y;              *p=z;          }          void showdata()          {              std::cout << “value of a is : ” <<a<< std::endl;              std::cout << “value of b is : ” <<b<< std::endl;              std::cout << “value of *p is : ” <<*p<< std::endl;          }      };      int main()      {        Demo d1;        d1.setdata(4,5,7);        Demo d2 = d1;        d2.showdata();        return 0;      }  Demo d2 = d1; calls the copy constructor defined by the user. It creates the exact copy of the value types data and the object pointed by the pointer p. Deep copy does not create the copy of a reference type variable.

C++ Copy Constructor Read More »

Bootstrapping in UNIX / LINUX

Bootstrapping in computer science is the technique for producing a self-compiling compiler. That is compiler/assembler written in the source programming language that it intends to compile. An initial core version of the compiler is generated in a different language mostly assembly language. Successive developed versions of the compiler are developed using this minimal subset of the language. When a computer is turned on is booted up with the code that is stored in ROM. The same code tries to figure out how much to load and start your kernel. The kernel verifies all the system’s hardware and initializes the system’s init process, which is always PID 1. A lot of things will happen before a login prompt can appear for the user to log in. File systems must be checked and mounted, and the system daemons started. These procedures are managed by a series of shell scripts that are run in sequence in init. The above entire process is called as Booting process. There are two ways where a UNIX / LINUX OS can boot, ‘Automatic mode’ & ‘Manual mode’ Without any external assistance if the system performs the whole boot procedure, then it is called ‘Automatic Mode’. In ‘manual mode’, at first, the system follows the automatic procedure up to a point before most initialization scripts have been run, And then turns control over to an operator. Up to this point, the computer will be running in ‘Single User mode’. Most of the system process will not be running, while other users cannot log in as well. It is involved in six different steps:

Bootstrapping in UNIX / LINUX Read More »

Big Data Processing with Hadoop, Spark, or Both?

Hadoop and Spark are the frameworks used for data processing. Both Hadoop and Spark are maintained by Apache Software Foundation. Both of these frameworks work on different principles. Hadoop is a common or popular name in the world of Big Data while Spark is still building a name for itself in a ”style”. Hadoop: Hadoop is an Open Source software framework for storing data and running applications on a cluster. It is very useful in Big Data Analytics with great Volume, Velocity, Variety, and Value known as the 4V’s of Big Data. Data in various forms such as structured, semi-structured and unstructured data. Hadoop has mainly four core components that work on different essential tasks for Big Data analysis. Distributed File System: Hadoop has its own distributed file system(HDFS) for storing the data. Map Reduce: Data store in the HDFS is processed or investigated using map-reduce. YARN: combines central resource manager that manages the node manager agents that monitors the processing of individual clustering nodes. Hadoop Common: It helps the user read and analyse the collected data in various systems Hadoop is a great tool when it comes to big data analysis for applicability, flexibility, availability. Spark : Spark is a framework that provides a number of interconnected platforms systems and standards for big data analysis. The important difference to be noted between Hadoop and Spark is that spark processes data through logical memory and RAM. While Hadoop works with disks. Spark is pretty much like Hadoop as a layer that can load data into memory with parallel analysis. The major cor components of Spark : Spark Streaming: The real-time data streaming where data is in bulk. It helps you analyze the ocean of data. Spark Core: Distributes tasks and works with scheduling. Spark Machine Learning Library (MLlib): An extensive library of an analytic algorithm for spark clusters, adaptable to all other clusters Spark can work with. Conclusion on Hadoop, Spark or Both? When Hadoop is compared with spark, the spark is much speedier than Hadoop. Hadoop focuses on transferring data through hard disks, spark runs its operations through memory. Working through logical RAM increases the speed. Hence, the spark can handle data analysis quite faster than Hadoop. But, spark lacks a file system and it hence needs Hadoop. To get spark work without Hadoop one would need to go with the third party file organization system. However, this is complicating and since both Hadoop and spark are maintained by Apache Software Foundation it is implied that using spark on top of Hadoop is the best long time solution.

Big Data Processing with Hadoop, Spark, or Both? Read More »

Enquire Now

Enquire Now

Enquire Now

Please Sign Up to Download

Please Sign Up to Download

Enquire Now

Please Sign Up to Download




    Enquiry Form