<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C Tutorials | Student Projects</title>
	<atom:link href="https://studentprojects.in/category/software-development/c-tutorials/c-tutorials-c-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Sat, 10 Dec 2022 04:22:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>C Pre-processor</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-pre-processor/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-pre-processor/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Tue, 29 Nov 2022 02:38:00 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[C pre-processor]]></category>
		<category><![CDATA[compilation]]></category>
		<category><![CDATA[assembly]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9781</guid>

					<description><![CDATA[<p>The C program&#8217;s textual form is transformed into an executable file by the compiler. The C programme must go through four stages before it can be run. Pre-processing, compilation, assembly, and linking are some of them. Pre-processing include taking out the comments, expanding the macro, and expanding the inclusion files. Instructions at the assembly level</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-pre-processor/">C Pre-processor</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The C program&#8217;s textual form is transformed into an executable file by the compiler. The C programme must go through four stages before it can be run. Pre-processing, compilation, assembly, and linking are some of them. Pre-processing include taking out the comments, expanding the macro, and expanding the inclusion files. Instructions at the assembly level are produced during the compilation phase. While the function calls are resolved in linking, the assembly level instructions are translated into machine code during the assembly phase.</p>



<p><strong>A C Pre-processor: What Is It?</strong></p>



<p>The compiler does not include the C Pre-processor. The C Pre-processor is merely a text replacement tool that tells the compiler to perform any necessary pre-processing prior to the compilation process. The C Pre-processor is referred to as CPP.</p>



<p>The block structure of the programme is unimportant; pre-processor directives like #include take effect as soon as they are noticed and continue to function until the end of the file that includes them. Pre-processing instructions in a C programme are lines that begin with the hash symbol &#8220;#.&#8221; The directive name is immediately followed by the hash symbol &#8220;#&#8221;. For instance, &#8220;#include.&#8221; &#8216; The hash symbol &#8220;#&#8221; may be placed before or after whitespace.</p>



<figure class="wp-block-table"><table><tbody><tr><td><strong>Directive</strong></td><td><strong>Description</strong></td></tr><tr><td>#include</td><td>This directive will insert a particular header from another file.</td></tr><tr><td>#define</td><td>This will substitute a pre-processor macro.</td></tr><tr><td>#undef</td><td>Using #undef, we can undefine a pre-processor macro.</td></tr><tr><td>#ifdef</td><td>It will return true if this macro is defined.</td></tr><tr><td>#if</td><td>It will test if a compile time condition is true.</td></tr><tr><td>#elif</td><td>Using #elif, we can define #else and #if in one statement</td></tr><tr><td>#endif</td><td>It will end pre-processor conditional</td></tr><tr><td>#error</td><td>Using #error, we can print the error message on stderr.</td></tr><tr><td>#pragma</td><td>It will issue the special commands to the compiler, using a standardized method.</td></tr></tbody></table></figure>



<p>The pre-processor, a kind of automatic editor that alters our source code before sending it to the compiler to translate into machine language code, is the first step in compiling the C programme. The pre-job processor&#8217;s includes removing all comments, which the compiler would otherwise disregard. Additionally, the pre-processor reacts to code directives like #define, #include, or #elif, which instruct the pre-processor on how to modify the source code before handing it off to the compiler.</p><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-pre-processor/">C Pre-processor</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-pre-processor/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Storage classes</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/storage-classes/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/storage-classes/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Mon, 28 Nov 2022 08:31:00 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[static variable]]></category>
		<category><![CDATA[automatic variables]]></category>
		<category><![CDATA[Storage class]]></category>
		<category><![CDATA[external variables]]></category>
		<category><![CDATA[resgister variables]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9777</guid>

					<description><![CDATA[<p>&#8220;A storage class defines a variable&#8217;s lifetime, default initial value, and scope.&#8221; The variable&#8217;s accessibility in these contexts is referred to as scope. Both the initial default value and the lifetime of a variable relate to the value that was there by default before the variable was initialised. Let&#8217;s move on to its types now</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/storage-classes/">Storage classes</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>&#8220;A storage class defines a variable&#8217;s lifetime, default initial value, and scope.&#8221;</p>



<p>The variable&#8217;s accessibility in these contexts is referred to as scope. Both the initial default value and the lifetime of a variable relate to the value that was there by default before the variable was initialised.</p>



<p>Let&#8217;s move on to its types now that we are familiar with the fundamental idea of storage classes. Depending on the kind of variables they hold, there are four different sorts of storage classes. The various storage classes are as follows. Their names give away the stored variables:</p>



<ul><li>Automatic Variables</li><li>External Variables</li><li>Static Variables</li><li>Register Variables</li></ul>



<p><strong>Auto Storage Class:</strong></p>



<p>This category applies automatically to variables that are created as part of a function but whose storage class has not yet been defined. As it can only be accessed within the function it is initialised in, its scope is minimal. Nothing else can access it. The variable initially holds a trash value until a value is assigned to it. Their lifespan is the amount of time till the function block ends, hence it depends on the duration of the function block.</p>



<div class="is-layout-flow wp-block-group"><div class="wp-block-group__inner-container">
<pre class="wp-block-code"><code lang="c" class="language-c">int a;
auto int a;
//Both are the same.
</code></pre>
</div></div>



<p><strong>External Storage Class:</strong></p>



<p>Because these variables are defined externally to the function, they can be used anywhere inside the function, making them universally applicable. Their starting value is zero. Their lifetime is equivalent to the duration of the programme because they can be used at any moment. It&#8217;s not usually a good idea to have too many global variables in a programme because they can compromise security.</p>



<p><strong>Extern Keyword:</strong></p>



<p>Use of the extern keyword tells the compiler that the variable has previously been defined somewhere else. By doing this, we may access the same variable in another file without allocating new memory and use it with the same space. Since we must use the extern keyword and it will automatically access it from the other file, its syntax is straightforward.</p>



<p>Syntax:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">extern int a;</code></pre>



<p><strong>Static Storage Class:</strong></p>



<p>Static variables are a little more technical because they are only valid for the function they are initialised in throughout the entire programme. It is useful when we modify the program&#8217;s value since the new value will be stored and overwritten by the old one. Their syntax is relatively simple because we just need to apply the Static keyword during initialization, and their initial default value is 0.</p>



<p>Syntax:</p>



<pre class="wp-block-code"><code class="">static int a;</code></pre>



<p><strong>Register Storage Class:</strong></p>



<p>As its scope is restricted to the function it is defined in, its initial default value is 0, and its lifetime is limited to the end of the function block, the Register Storage Class is very similar to the Auto Storage Class. Now, the main distinction between it and the others is that it seeks rapid access to the CPU&#8217;s register memory rather than the local memory. It is typically used for programmes that must be accessed more quickly than others or that are frequently used.</p>



<p>Syntax:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">register int a;</code></pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/storage-classes/">Storage classes</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/storage-classes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Allocation of memory using the heap</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/allocation-of-memory-using-the-heap/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/allocation-of-memory-using-the-heap/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Mon, 28 Nov 2022 06:24:00 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[malloc]]></category>
		<category><![CDATA[calloc]]></category>
		<category><![CDATA[Allocation of memory using the heap]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9775</guid>

					<description><![CDATA[<p>We have four functions for the allocation of memory utilising the heap: Malloc Calloc Realloc Free malloc(): Memory allocation is referred to as malloc. It asks memory from the heap and returns a reference to the memory, as implied by its name. We can typecast the pointer for any variables because it is of the</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/allocation-of-memory-using-the-heap/">Allocation of memory using the heap</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>We have four functions for the allocation of memory utilising the heap:</p>



<ul><li>Malloc</li><li>Calloc</li><li>Realloc</li><li>Free</li></ul>



<p>malloc():</p>



<ul><li>Memory allocation is referred to as malloc. It asks memory from the heap and returns a reference to the memory, as implied by its name. We can typecast the pointer for any variables because it is of the void type. At the time of allocation, all values are initialised to null values. Its syntax is straightforward because we only need to specify the memory space and the desired size in bytes.</li></ul>



<p>Syntax:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">ptr = (ptr-type*) malloc(size_in_bytes)</code></pre>



<p>Example:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">int *ptr;
ptr = (int*) malloc (3* sizeof(int))
</code></pre>



<p>calloc():</p>



<ul><li>Contiguous allocation is referred to as calloc. The two key distinctions are that it also asks for memory from the heap, returns a pointer to the memory, and has the same functionality as malloc(). The required number and size of blocks must be sent as parameters. The second distinction is a significant one. In other words, calloc() initialises the variables to 0 rather than a trash value at the moment of allocation.</li></ul>



<p>Syntax:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">ptr = (ptr-type*) calloc(n,size_in_bytes) ptr = (ptr-type*) calloc(n,size_in_bytes)</code></pre>



<p>Example:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">int *ptr;
ptr = (int*) malloc (10, sizeof(int))
</code></pre>



<p>realloc():</p>



<ul><li>Reallocation is the definition of realloc. It is employed when dynamic memory is insufficient or when extra memory needs to be allocated in order to hold more data. Its syntax is straightforward because all we have to do is provide the information relating to the pointer while overwriting the memory that has already been allocated as a function parameter.</li></ul>



<p>Syntax:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">ptr = (ptr-type*) realloc(ptr,new_size_in_bytes)</code></pre>



<p>Example:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">ptr = (int*) realloc (ptr, 5* sizeof(int))</code></pre>



<p>Free():</p>



<ul><li>As was said earlier when discussing the drawbacks of dynamic memory allocation, there is no automatic method for releasing the memory space that has been allocated. Therefore, the allocated memory&#8217;s space is released using the free function. Since we must send the pointer as a parameter inside the function, its syntax is the simplest of all.</li></ul>



<p>Syntax:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">free(ptr)</code></pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/allocation-of-memory-using-the-heap/">Allocation of memory using the heap</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/allocation-of-memory-using-the-heap/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Wild pointers</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointers/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointers/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Sun, 27 Nov 2022 10:35:00 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[Dereferencing]]></category>
		<category><![CDATA[Wlid pointers]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9779</guid>

					<description><![CDATA[<p>Even though a wild pointer is a straightforward idea, you still needed a separate tutorial to understand it. Let&#8217;s begin with the definition, then. &#8220;Void pointers are uninitialized pointers.&#8221; Example: In the example above, a pointer was generated but left empty, turning it into a wild pointer. Its drawback is that it will hold any</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointers/">Wild pointers</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Even though a wild pointer is a straightforward idea, you still needed a separate tutorial to understand it. Let&#8217;s begin with the definition, then.</p>



<p>&#8220;Void pointers are uninitialized pointers.&#8221;</p>



<p>Example:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">int *ptr;</code></pre>



<p>In the example above, a pointer was generated but left empty, turning it into a wild pointer.</p>



<p>Its drawback is that it will hold any garbage value, which means it will hold any random portion of memory. Numerous faults in the software may result from the storage of data in an arbitrary location, and occasionally the programmer will not even be able to determine the source.</p>



<p>Solution: We would rather convert a void pointer to a NULL pointer in order to prevent the flaws and errors it may introduce into a programme. As a result, our pointer will always point to 0 or NULL instead of any memory location. Simply setting a wild pointer equal to NULL will make it a NULL pointer. Let&#8217;s look at it using C syntax.</p>



<p>Syntax:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">int *ptr = NULL;</code></pre>



<p>Therefore, if we are not utilising our pointer to point at a specific memory region, we will use this way.The pointer can now be initialised as a second option for preventing similar issues.</p>



<p>Example:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">int x = 3;
int *ptr;
ptr = &amp;3;
</code></pre>



<p>It will be a wild pointer if we simply run the first two lines of the aforementioned section of code because no value has been initialised to it. However, if we run the third line as well, it will point to a specific address and become a normal pointer.</p>



<p>Dereferencing:</p>



<p>We are unable to dereference a wild pointer because we are unsure of the data that it is pointing to in memory. Dereferencing a wild pointer can result in several problems as well as programme failure.</p>



<pre class="wp-block-code"><code lang="c" class="language-c">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
int main()
{
    int a =4354;
    int *ptr; // This is a wild pointer
    // *ptr = 34; // This is not a good thing to do
    ptr = &amp;a; // ptr is no longer a wild pointer
    printf("The value of a is %d\n", *ptr);
    return 0;
}
</code></pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointers/">Wild pointers</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Dynamic memory allocation</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dynamic-memory-allocation/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dynamic-memory-allocation/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Sun, 27 Nov 2022 06:23:00 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[Dynamic memory allocation]]></category>
		<category><![CDATA[memory allocation in c]]></category>
		<category><![CDATA[dynamic memory]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9772</guid>

					<description><![CDATA[<p>Describe dynamic memory. The process of allocating memory at runtime is known as dynamic memory allocation. The idea of dynamic memory allocation is used to minimise memory waste and is the best method of memory allocation. We&#8217;ll look at the C programming language&#8217;s memory structure to fully understand the idea. Memory Allocation in C: There</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dynamic-memory-allocation/">Dynamic memory allocation</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Describe dynamic memory.</p>



<ul><li>The process of allocating memory at runtime is known as dynamic memory allocation. The idea of dynamic memory allocation is used to minimise memory waste and is the best method of memory allocation. We&#8217;ll look at the C programming language&#8217;s memory structure to fully understand the idea.</li></ul>



<p>Memory Allocation in C:</p>



<ul><li>There are four different parts to memory allocation in C. Because understanding each of them is essential for understanding memory layout, we shall go into detail about each of them.</li></ul>



<p>Code:</p>



<ul><li>All of our program&#8217;s text segments are composed of code. Since we are already familiar with this section, we won&#8217;t go into more depth about it.</li></ul>



<p>Variable</p>



<ul><li>We refer to both global and static variables as variables. While static variables have restrictions inside the function, global variables can be utilised elsewhere in the programme. Depending on the amount of data they can store, the variable section is further separated into two segments.</li></ul>



<p>Data segment: </p>



<ul><li>Stores data that has already been initialised, or whose value has been determined.</li></ul>



<p>Example:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">int i = 0;</code></pre>



<p>The bss segment stores uninitialized data, or data whose variables have not yet been initialised.</p>



<p>Example:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">int i = 0;</code></pre>



<p>Stack:</p>



<ul><li>A LIFO data structure is the stack. It grows in size as the programme progresses.</li><li>The stack initially resembles a bucket, where the last item entered will be the first one to emerge. Because of this, it is known as a LIFO data structure, or last in, first out, structure.Consider adding function A to the stack. The execution of Function A will begin. As it continues to run, function A is now calling function B. The programme will begin executing Function B after pushing B into the stack. If B now calls a different function C, the programme will add C to the stack and begin C&#8217;s execution.Now that C has finished running through its whole, the programme will remove C from the stack (because it was the last one to enter) and begin running B. After B has finished running entirely, it will be pushed out, and A will then begin running until the stack is empty.</li></ul>



<p>Stack overflow:</p>



<ul><li>Stack Overflow is a phenomena that occurs when a stack runs out of space due to poor programming or a logical mistake.</li></ul>



<p>Heap:</p>



<ul><li>Heap is a data structure that is built on trees. When we allocate memory dynamically, its size grows. We must establish a pointer in our main function that points to a memory block in a heap in order to use the heap data structure. The drawback of using heap is that when the pointer is rewritten, the memory does not immediately free itself.</li></ul>



<p></p>



<pre class="wp-block-code"><code lang="c" class="language-c">#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int i;
int main()
{
    int id;
    return 0;
}
&nbsp;</code></pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dynamic-memory-allocation/">Dynamic memory allocation</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dynamic-memory-allocation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>C Static Variables</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-static-variables/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-static-variables/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Tue, 25 Oct 2022 09:04:59 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[static variable]]></category>
		<category><![CDATA[worldwide variable]]></category>
		<category><![CDATA[c static variable]]></category>
		<category><![CDATA[local variable]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9711</guid>

					<description><![CDATA[<p>A.Local Variables Variables declared within a function or a block of code are referred to as local variables. These variables are only accessible within the function in which they were declared. Local variables have a function-specific scope since they can only be accessed by statements that are included within that function or code block. B.</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-static-variables/">C Static Variables</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><strong>A.Local Variables</strong></p>



<ul><li>Variables declared within a function or a block of code are referred to as local variables. These variables are only accessible within the function in which they were declared. Local variables have a function-specific scope since they can only be accessed by statements that are included within that function or code block.</li></ul>



<p><strong>B. Worldwide Variables</strong></p>



<ul><li>Global variables are those that have definitions separate from any and all functions. We can access global variables within any of the program&#8217;s declared functions to retrieve their values. The system initialises global variables when they are defined. When a name is defined for both local and global variables, the local variable is given preference.</li></ul>



<p><strong>C. Static Variables</strong></p>



<ul><li>One definition of a static variable is one that keeps its value even after the programme leaves the scope in which it was declared. Static variables don&#8217;t need to be initialised afresh in the new scope; they keep their value. Static variables retain their memory until the program&#8217;s end, but regular variables are deleted when the function they were declared in is exited. Both inside and outside of the function they can be declared. The block is the local area for static variables. A static variable&#8217;s default value is zero. A static variable is declared with the word static.</li></ul>



<p><strong>Output:</strong></p>



<p>static datatype variable_name = variable_value;</p>



<p>Static global variables differ from static local variables.</p>



<p><strong>Static global variable</strong></p>



<ul><li>Static global variables are any variables with the static keyword specified outside of a function. Any method in the application will allow access to this variable.</li></ul>



<p><strong>Static local variable</strong></p>



<ul><li>Static local variables are any variables that are declared with the static keyword inside of a function. A static local variable has the same scope as a local variable, but its memory is accessible for the duration of the program&#8217;s execution.</li></ul>



<p><strong>The characteristics of static variables</strong></p>



<ul><li>A static variable&#8217;s value will remain after the programme leaves the scope in which it was declared.</li><li>A static variable&#8217;s allotted memory is accessible for the duration of the program&#8217;s execution.</li><li>A static variable&#8217;s default value is 0 if we don&#8217;t initialise it.</li></ul><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-static-variables/">C Static Variables</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-static-variables/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Wild Pointer</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointer/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointer/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Tue, 25 Oct 2022 09:03:44 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[Dereferencing]]></category>
		<category><![CDATA[Avoiding problems due to WILD pointers]]></category>
		<category><![CDATA[Wild pointers]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9708</guid>

					<description><![CDATA[<p>Wild pointers are uninitialized pointers that point to any random position in memory while being unassigned from any other memory location. This could occasionally result in a programme crashing or acting erratically. For instance: A pointer called ptr is generated in this example, but it is empty. The pointer ptr is now a wild pointer</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointer/">Wild Pointer</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Wild pointers are uninitialized pointers that point to any random position in memory while being unassigned from any other memory location. This could occasionally result in a programme crashing or acting erratically.</p>



<p><strong>For instance:</strong></p>



<pre class="wp-block-code"><code lang="c" class="language-c">int *ptr;</code></pre>



<p>A pointer called ptr is generated in this example, but it is empty. The pointer ptr is now a wild pointer as a result. Declaring a pointer without initialising it has drawbacks of its own. One such drawback is that it will save any worthless information in it. It will hold in it arbitrarily a position in memory. This random allocation frequently becomes difficult for a programmer to debug, leading to several issues with the program&#8217;s operation.</p>



<p><strong>A. Avoiding problems due to WILD pointers</strong></p>



<p>In order to avoid problems that can arise while dereferencing a wild reference, we frequently opt to change a void pointer to a NULL pointer. By doing this, our pointer will instead point to a NULL position rather than any trash memory location. Simply setting a wild pointer equal to NULL will make it a NULL pointer.</p>



<p><strong>B. Dereferencing</strong></p>



<p>A wild pointer cannot be dereferenced since we are unsure of the data it is pointing at in memory. Dereferencing a wild pointer can result in numerous problems as well as a software crash.</p>



<p><strong>Example</strong>:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">#include &lt;bits/stdc++.h&gt;
using namespace std;

int main() {
   int *arr;
   for(int i=0; i&lt;5 ; i++)
   cout &lt;&lt; arr[i] &lt;&lt; ” “;
   return 0;
}</code></pre>



<p><strong>Output</strong>:1 0 -426634956 32764 0</p><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointer/">Wild Pointer</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/wild-pointer/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Dangling Pointer</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dangling-pointer-2/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dangling-pointer-2/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Tue, 25 Oct 2022 09:02:07 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[Function Call]]></category>
		<category><![CDATA[releasing or deleting temporary memory]]></category>
		<category><![CDATA[dangling pointer]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9706</guid>

					<description><![CDATA[<p>Dangerous pointers are those that point to memory locations that have already been erased or released. During object deletion, dangling pointers are frequently created. When an object with an incoming reference is removed or de-allocated without changing the pointer&#8217;s value, this occurs. The pointer is still pointing at the deallocated memory&#8217;s address in memory. The</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dangling-pointer-2/">Dangling Pointer</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Dangerous pointers are those that point to memory locations that have already been erased or released. During object deletion, dangling pointers are frequently created. When an object with an incoming reference is removed or de-allocated without changing the pointer&#8217;s value, this occurs. The pointer is still pointing at the deallocated memory&#8217;s address in memory. The system may reallocate the previously deleted memory by itself, which may lead to a number of unexpected outcomes because the memory may now contain different data. The following causes contribute to dangling pointers:</p>



<p><strong>Releasing or deleting temporary memory</strong></p>



<ul><li>The pointer continues to point to freed space even after memory is deallocated. Here&#8217;s an illustration to show how that occurs:</li></ul>



<pre class="wp-block-code"><code lang="c" class="language-c">#include &lt;stdio.h>
int main()
{
    int a = 80;
    int *ptr = (int *)malloc(sizeof(int));
    ptr = &amp;a;
    free(ptr);
    return 0;
}</code></pre>



<p>The code shown above shows how to construct a variable pointer *ptr and an integer variable a with the value 80. The malloc() function is used to generate the pointer variable *ptr. Given that we are aware that the malloc() function produces a void, we type-convert the void pointer into an int pointer using the int * function.</p>



<p><strong>Function Call</strong></p>



<ul><li>We will now examine how the function call causes the pointer to become dangling.</li></ul>



<pre class="wp-block-code"><code lang="c" class="language-c">#include &lt;stdio.h>
int *myvalue()
{
    int a = 10;
    return &amp;a;
}

int main()
{
    int *ptr = myvalue();
    printf(“%d”, *ptr);
    return 0;
}</code></pre>



<p><strong>Output: Segmentation Fault!</strong></p>



<p>The func() method&#8217;s return value is contained in the pointer ptr, which is declared in the main() function of the code above. The programme control is transferred to the context of the int *func when the function func() is called (). The address of the integer variable an is then returned by the method func().</p>



<p>The integer variable an is no longer accessible for the remainder of the program&#8217;s execution at this point, and programme control returns to the main() function. And because it points to a memory location that has been removed or freed from the stack, the pointer ptr becomes dangling. The application consequently causes a segmentation fault.</p>



<p>The outcome would have been 10 had the code been modified and the integer variable, which is static and is declared globally, been local rather than global.</p>



<p>The best way to prevent dangling pointer errors</p>



<p>Our applications get unpleasant defects from the hanging pointer, and these issues frequently lead to security flaws. These errors that result from the generation of a dangling pointer can be prevented by simply initialising the pointer value to NULL. The pointer won&#8217;t then point to the space in memory that was freed. While the purpose of giving the pointer the NULL value was to prevent it from pointing to any previously or arbitrarily designated memory location.</p><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dangling-pointer-2/">Dangling Pointer</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/dangling-pointer-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>NULL Pointer in C</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/null-pointer-in-c/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/null-pointer-in-c/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Tue, 25 Oct 2022 08:59:40 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[Null pointer in C]]></category>
		<category><![CDATA[Defeating a reference to NULL]]></category>
		<category><![CDATA[Uninitialized pointer versus NULL pointer]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9704</guid>

					<description><![CDATA[<p>A NULL pointer is a pointer that has no value or memory address assigned to it; it is just NULL. None of the variables, functions, or objects can be referenced by a NULL pointer. When we want to show that a pointer variable isn&#8217;t yet assigned to a valid memory address, we frequently initialise pointer</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/null-pointer-in-c/">NULL Pointer in C</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>A NULL pointer is a pointer that has no value or memory address assigned to it; it is just NULL. None of the variables, functions, or objects can be referenced by a NULL pointer. When we want to show that a pointer variable isn&#8217;t yet assigned to a valid memory address, we frequently initialise pointer variables with NULL pointers.</p>



<pre class="wp-block-code"><code lang="c" class="language-c">int *ptr = NULL;</code></pre>



<p>Simply put, no memory is allocated to a NULL pointer because it often corresponds to the NULL or 0th memory location.</p>



<p><strong>Defeating a reference to NULL</strong></p>



<ul><li>A NULL pointer behaves very similarly to a void pointer when dereferencing. Since a NULL pointer is really a VOID pointer in and of itself, we must typecast it into any data type before dereferencing. Failure to do so causes a compile-time error.</li></ul>



<p><strong>Uninitialized pointer versus NULL pointer</strong></p>



<ul><li>Null pointers are distinct from uninitialized pointers since they take up no memory space. In other words, it only points to the zeroth position. An uninitialized pointer, on the other hand, signifies that the pointer resides at a garbage value address. Since the garbage value address still refers to a legitimate memory location, it is not a NULL value. Therefore, NULL pointers are chosen to be on the safe side.</li></ul>



<p><strong>Void pointer versus NULL pointer</strong></p>



<ul><li>Due to their similar names, NULL pointers and void pointers may appear to be quite similar; nevertheless, a NULL pointer is a pointer with a NULL value address, and a void pointer is a pointer of void data type. Their respective meanings diverge.</li></ul>



<p><strong>example of a NULL pointer :  </strong></p>



<pre class="wp-block-code"><code lang="c" class="language-c"> int *ptr = NULL;</code></pre>



<p>example of a VOID pointer:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">    void *ptr;</code></pre>



<p><strong>Benefits of using a NULL pointer</strong></p>



<ul><li>A pointer variable can be initialised without having a specific memory location assigned to it.</li><li>It can be used to determine whether a pointer is genuine or not. Making the pointer NULL, which prevents dereference, allows us to verify that.</li><li>When comparing two pointers, a NULL pointer is used to determine whether the other pointer is actually pointing to a memory address or not.</li><li>In the case of C programming, we employ it for error management.</li><li>When passing a pointer with a valid memory location is not desired, we can give a NULL pointer instead.</li></ul><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/null-pointer-in-c/">NULL Pointer in C</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/null-pointer-in-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>C VOID Pointer</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-void-pointer/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-void-pointer/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Tue, 25 Oct 2022 08:56:40 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[features of a VOID pointer]]></category>
		<category><![CDATA[c Void in pointer]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9701</guid>

					<description><![CDATA[<p>After a brief overview of pointers, it is time to begin with void pointers and their functionalities, which are a highly significant sort of pointers. Since functions that return nothing are given the type void, we already know that a void function has no return type. Pointers that have the datatype of a void can</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-void-pointer/">C VOID Pointer</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>After a brief overview of pointers, it is time to begin with void pointers and their functionalities, which are a highly significant sort of pointers. Since functions that return nothing are given the type void, we already know that a void function has no return type. Pointers that have the datatype of a void can now be typecast into any other data type as needed in the case of those pointers. And that helps since it eliminates the need for us to first choose a data type for the pointer. General-purpose pointer variables can also be used to refer to void pointers. Let&#8217;s look at a few instances that show how void pointers can be used.</p>



<p>&nbsp;&nbsp;&nbsp; int var = 1;</p>



<p>&nbsp;&nbsp;&nbsp; void *voidPointer = &amp;var;</p>



<p>Since we have stored the address of an integer value in the void pointer, its data type is typecast here into int.</p>



<p>&nbsp;&nbsp;&nbsp; char x = &#8216;a&#8217;;</p>



<p>&nbsp;&nbsp;&nbsp; void *voidPointer = &amp;x;</p>



<p>As we have saved the address of a character value in the void pointer in this example, the data type of the pointer is typecast to char. You must also be reminded of how we used to type cast void pointers provided by the calloc() and malloc() routines while doing dynamic memory allocation. The heap also returns a void pointer to the requested memory there. A void pointer is useful in this situation since we could type cast the object to any other data type.</p>



<p>Two important features of a VOID pointer are:</p>



<p>Pointers that are void cannot be dereferenced. An illustration of this is possible with the aid of an example.</p>



<pre class="wp-block-code"><code lang="c" class="language-c">int a = 10;
    void *voidPointer;
    voidPointer = &amp;a;
    printf("%d", *voidPointer);
</code></pre>



<p>OUTPUT: Compiler Error!</p>



<p>The fact that we cannot dereference a void pointer, which would require us to typecast the pointer each time it is used, causes his programme to crash at compilation time. This is the right way to do things.</p>



<pre class="wp-block-code"><code class="">    int a = 8;
    void *voidPointer;
    voidPointer = &amp;a;
    printf("%d", *(int *)voidPointer);</code></pre>



<p>Output:8</p>



<p>Due to the use of the type and the pointer, the compiler won&#8217;t produce any errors and will output the result immediately.</p>



<p>Since void pointers don&#8217;t retain any addresses, they can&#8217;t be utilised with pointer arithmetic to increase or decrease their value.</p><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-void-pointer/">C VOID Pointer</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/c-void-pointer/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
